Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpmailer can't add a reply to address

Tags:

php

phpmailer

I am trying to add a reply to address to my php mailer and it just puts from "me" and replies to my address.

Any ideas what I am doing wrong? I have added the $mail->AddReplyTo. I want it to reply to the sender of the web form.

$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";
like image 435
Roscoeh Avatar asked Oct 21 '10 14:10

Roscoeh


People also ask

How many emails can I send with PHPMailer?

PHPMailer does not set any limits, nor does the mail() function, it's only ISPs like GoDaddy that do. However, they do so by blocking access to normal SMTP ports, and/or redirecting SMTP connections to their own servers ( *. secureserver. * ).

Why does mail go to spam in PHPMailer?

usually this happens because the sending server is already marked as spam by somebody. The way i found is go to the gmail account mark the item as 'important' in gmail and 'Add to Safe senders' in Outlook. Save this answer. Show activity on this post.

Does PHPMailer work on localhost?

The way you have setup your PHPMailer, it would require an SMTP server running on your localhost to send the messages. If you don't have an SMTP server running on your localhost, then you can use an external SMTP server to relay the messages through.


1 Answers

Something to try is to make sure your $email and $name variables are being passed in correctly (add some debugging statements to echo them out). Not sure if you have done that or if you are checking if the form has posted or not. But that would be step one.

From my workings with PHPMailer and GMail, they do not work to well. Instead I would suggest trying the phpGMailer script. It works great for GMail. See if that does not fix your issues.

UPDATE

Thinking about it, I do not think GMail permits the changing of the ReplyTo address unless the GMail account has activated authorization for that account. I am not 100% sure on this, but I know through the web interface that is not possible.

Off Topic

I would avoid using eregi_replace it is depreciated. I would use preg_replace instead. Here is an updated version so you can update your code:

$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);
like image 134
Jim Avatar answered Sep 28 '22 03:09

Jim