PHPMailer Gmail SMTP联系我们表格AddReplyTo

时间:2012-07-31 10:59:54

标签: php smtp gmail phpmailer

我有以下代码。正如您所见,我将replyTo字段设置为联系我们表单中输入的电子邮件。但是这不起作用。每当我收到来自联系表单的电子邮件时,我都需要复制电子邮件(位于我的邮件正文中)并将其粘贴到“收件人”字段中。由于to字段将忽略我放置不同的回复电子邮件并简单地使用我的网站电子邮件的事实。知道什么可能是错的吗?

require_once('mailer/class.phpmailer.php');

$mail             = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "email";  // GMAIL username
$mail->Password   = "password";            // GMAIL password

$mail->SetFrom("mywebsitesemail", "my name");
$mail->AddAddress("mywebsitesemail", "my name");
$mail->AddReplyTo("$email","$name");

$mail->Subject    = "Subject";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML("$message");



$mail->Send();

0 个答案:

没有答案