htmlentities 在使用 PHPmailer 时忽略 <br>
htmlentities ignores <br> when using PHPmailer
前段时间我做了一个联系表来发送电子邮件。
我有这个:
If ($validity !='Good@Ripsi'){
$to = "contact-us@xx-xxxx.com";
$subject = "xx xxxx new Subscriber";
$email_address = htmlentities($_GET['email_address']);
$headers = "xxxxxxxxxx" . "\r\n" .
mail($to,$subject,$email_address,$headers);
header("Location: index.php");
}
而且效果很好。在我读到虽然我不打算发送数以千计的 Newletters 之后,最好使用 PHPmailer,否则它可能被视为垃圾邮件并被阻止。我不太了解那些邮寄的东西。所以我读了一个教程,它工作得很好,但有一点:htmlentities 不再做这项工作,所有 <br>
在接待处都被忽略了。
我检查过:$mail->IsHTML(true);
将不胜感激。
这是使用 PHPMailer 的代码:
<?php
require "phpmailer/PHPMailer/PHPMailerAutoload.php";
define("DB_HOST","localhost");
define("DB_USERNAME","xxxx_xxxx");
define("DB_PASSWORD","xxxx");
define("DB_NAME","xxxxxx");
$conn = mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME) or die (mysqli-error());
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
function smtpmailer($to, $from, $from_name, $subject, $body)
{
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'mail.xxxxx.com';
$mail->Port = 465;
$mail->Username = 'newsletter@xxxxx.com';
$mail->Password = 'xxxxxxx';
$mail->IsHTML(true);
$mail->From="newsletter@xxxx.com";
$mail->FromName=$from_name;
$mail->Sender=$from;
$mail->AddReplyTo($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send())
{
$error ="Error Ocured...";
return $error;
}
else
{
$error = "Please wait!! Your email is being sent... ";
return $error;
}
}
$from = 'newsletter@ts-ripsi.com';
$name = 'xxxxxxx T & S';
$subj = 'Newsletter from xxx and xxxx';
$msg = htmlentities($_GET['message']);
$sqli = "SELECT ID, Email FROM mailing_addresses";
$record = mysqli_query($conn, $sqli);
while ($row = mysqli_fetch_array($record)) {
$to = $row['Email'];
$error=smtpmailer($to,$from, $name ,$subj, $msg);
}
header("Location: index.php");
?>
我不明白 IsHTML
的用法。在这种情况下,它必须设置为 false
.
前段时间我做了一个联系表来发送电子邮件。
我有这个:
If ($validity !='Good@Ripsi'){
$to = "contact-us@xx-xxxx.com";
$subject = "xx xxxx new Subscriber";
$email_address = htmlentities($_GET['email_address']);
$headers = "xxxxxxxxxx" . "\r\n" .
mail($to,$subject,$email_address,$headers);
header("Location: index.php");
}
而且效果很好。在我读到虽然我不打算发送数以千计的 Newletters 之后,最好使用 PHPmailer,否则它可能被视为垃圾邮件并被阻止。我不太了解那些邮寄的东西。所以我读了一个教程,它工作得很好,但有一点:htmlentities 不再做这项工作,所有 <br>
在接待处都被忽略了。
我检查过:$mail->IsHTML(true);
将不胜感激。
这是使用 PHPMailer 的代码:
<?php
require "phpmailer/PHPMailer/PHPMailerAutoload.php";
define("DB_HOST","localhost");
define("DB_USERNAME","xxxx_xxxx");
define("DB_PASSWORD","xxxx");
define("DB_NAME","xxxxxx");
$conn = mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME) or die (mysqli-error());
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
function smtpmailer($to, $from, $from_name, $subject, $body)
{
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'mail.xxxxx.com';
$mail->Port = 465;
$mail->Username = 'newsletter@xxxxx.com';
$mail->Password = 'xxxxxxx';
$mail->IsHTML(true);
$mail->From="newsletter@xxxx.com";
$mail->FromName=$from_name;
$mail->Sender=$from;
$mail->AddReplyTo($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send())
{
$error ="Error Ocured...";
return $error;
}
else
{
$error = "Please wait!! Your email is being sent... ";
return $error;
}
}
$from = 'newsletter@ts-ripsi.com';
$name = 'xxxxxxx T & S';
$subj = 'Newsletter from xxx and xxxx';
$msg = htmlentities($_GET['message']);
$sqli = "SELECT ID, Email FROM mailing_addresses";
$record = mysqli_query($conn, $sqli);
while ($row = mysqli_fetch_array($record)) {
$to = $row['Email'];
$error=smtpmailer($to,$from, $name ,$subj, $msg);
}
header("Location: index.php");
?>
我不明白 IsHTML
的用法。在这种情况下,它必须设置为 false
.