【发布时间】:2015-07-30 13:52:29
【问题描述】:
我用 PHPMailer 发送电子邮件,我的代码是:
$mail = new PHPMailer(true);
$mail->Mailer = "smtp";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 0;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Username = "nati323@gmail.com";
$mail->Password = "****";
$mail->addCustomHeader('Content-Type: text/plain; charset="utf-8"');
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->From = $from;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $msg;
return $mail->Send();
$msg 变量是一个函数参数,我这样使用它:
function sendMail ($to, $subject, $msg, $from, $add = null)
我是这样使用它的:
sendMail($_POST['mail'], $text['EMAIL_RECOVER_MSG_SUBJECT'], $text['EMAIL_RECOVER_MSG'], $from)
变量包含:
$text['EMAIL_RECOVER_MSG_SUBJECT'] = 'Password Recover: From dmworld24.com';
$text['EMAIL_RECOVER_MSG'] = 'You Forget Your Password To Recover it Please Go Into The Next Link:\r\n http://dmworld24.com/login.php?act=rec&token={TOKEN}&mail={MAIL} \r\n If You Didnt Ask For Password Recovering Just Ignore This Message';
$from = 'System@dmworld24.com';
现在我尝试在消息中添加换行符,例如:
You Forget Your Password To Recover it Please Go Into The Next Link:\r\n http://dmworld24.com/login.php?act=rec&token=7054343021*****353214&mail=nati323@gmail.com \r\n If You Didnt Ask For Password Recovering Just Ignore This Message
我在邮件中收到的内容是一样的,\r\n 显示为字符并且没有换行符,我做错了什么?
我遇到的另一个问题是表单方法有效,我向 nati323@gmail.com 发送电子邮件以尝试尝试,并使用 nati323@gmail.com 帐户连接到 smtp 服务器,我总是从我的自我,以及我定义的表单显示......
【问题讨论】:
-
你能提供你设置 $msg 的行吗?
-
@JonStirling 请看我的编辑