【问题标题】:phpmailer Error after sending Email发送电子邮件后phpmailer错误
【发布时间】:2014-09-01 11:22:34
【问题描述】:

代码:-

$mail  = new PHPMailer();
$body="<b>This mail is sent using PHP Mailer</b>";#HTML tags can be included
$mail->IsSMTP();
$mail->SMTPAuth  = true;                 #enable SMTP authentication
$mail->SMTPSecure = "tls";               #sets the prefix to the server
$mail->Host  = "smtp.gmail.com";         #sets GMAIL as the SMTP server
$mail->Port       = 587;                 #set the SMTP port
$mail->Username   = "morelifelondon@gmail.com";     #your gmail username
$mail->Password   = "***********";                  #Your gmail password
$mail->From = $email;    
$mail->FromName   = $name ;                
$mail->Subject    = "Enquiry";
$mail->Body    = $messages;
$mail->AddAddress("morelifelondon@gmail.com","contact");
$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Mail has Been Sent.';
}
}

我希望将 morelifelondon@gmail.com 替换为 abhishek@gmail.com。这可能吗 ?

【问题讨论】:

  • 该地址在您的代码中出现了两次,如果它在$email 中可能会出现第三次(您尚未提供完整的代码)。你没有说你想改变哪个实例,尽管你需要做的就是改变它们。

标签: php ssl smtp gmail phpmailer


【解决方案1】:
$mail->AddAddress("abhishek@gmail.com","contact");

或使用

$mail->AddCC("abhishek@gmail.com","contact");

【讨论】:

  • abhishek 是用户,我希望该用户的电子邮件出现在 morelifelondon@gmail.com $mail->From = $email;这段代码不起作用。
  • 所以你必须设置自己的标题。尝试将 From: 添加到标题 $headers = "" 。 “回复:” 。来自 . "\r\n" 。 “从:” 。来自 . "\r\n" 。 “X-Mailer:PHP/”。 php版本(); $headers .= 'MIME 版本:1.0' 。 "\r\n"; $headers .= '内容类型:文本/html;字符集=iso-8859-1' 。 "\r\n";
  • 不,不要设置您自己的标题 - 此代码使用 PHPMailer,它会为您完成。如果要更改发件人地址,只需设置$mail-&gt;From = 'abhishek@gmail.com';
  • @Synchro 通过设置 $mail->From ='abhishek@gmail.com' 不起作用;它仍然显示 morelifelondon@gmail.com,我已经粘贴了完整的代码。 $mail->来自 ='abhishek@gmail.com';和 $mail->From = $email;是一样的。我猜?
  • 我们不知道这是否是同一件事,因为您没有显示设置$email 的代码部分。
猜你喜欢
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
相关资源
最近更新 更多