2010-10-21 28 views
7

我想添加一个回复地址到我的PHP邮件程序,它只是从“我”和回复我的地址。phpmailer不能添加回复地址

任何想法我做错了什么?我添加了$ mail-> AddReplyTo。我希望它回复网页表单的发件人。

$name = $_POST['name']; 
$telephone = $_POST['telephone']; 
$email = $_POST['email']; 
$message = $_POST['message']; 

$body    = file_get_contents('phpmailer/contents.html'); 
$body    = eregi_replace("[\]",'',$body); 
$body    = eregi_replace("<name>", $name,$body); 
$body    = eregi_replace("<telephone>", $telephone, $body); 
$body    = eregi_replace("<email>", $email, $body); 
$body    = eregi_replace("<message>", $message, $body); 




$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "smtp.gmail.com"; // SMTP server 
        // 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 protected]"; // GMAIL username 
$mail->Password = "xxxxx"; 

$mail->AddReplyTo($email, $name); 


$address = "xxxx.net"; 

$mail->AddAddress($address, "Contact form"); 

$mail->Subject = " Contact Form"; 

回答

2

一些尝试是,以确保您的$email$name变量在正确传递(添加一些调试语句呼应出来)。不知道你是否已经这样做,或者如果你正在检查表格是否已经发布。但那将是第一步。

从我与PHPMailer和GMail的工作中,他们不能很好地工作。相反,我会建议尝试phpGMailer脚本。它适用于GMail。看看是否没有解决你的问题。

UPDATE

考虑这个问题,我不认为GMail的允许ReplyTo地址的变化,除非该Gmail帐户已经激活授权该帐户。我对此并不十分确定,但我通过网络界面知道这是不可能的。

关闭主题

我会避免使用eregi_replace它贬值。我会用preg_replace代替。这里是一个更新的版本,所以你可以更新你的代码:

$body    = file_get_contents('phpmailer/contents.html'); 
$body    = preg_replace("~[\]~",'',$body); 
$body    = preg_replace("~<name>~i", $name,$body); 
$body    = preg_replace("~<telephone>~i", $telephone, $body); 
$body    = preg_replace("~<email>~i", $email, $body); 
$body    = preg_replace("~<message>~i", $message, $body); 
+0

谢谢布拉德,这节省了我很多时间,认为你是正确的关于Gmail的回复。认为他只需要忍受它。 – Roscoeh 2010-10-22 05:29:16