I started to use PHPMailer on my website in order to set up a contact form (user -> my own email account). Everything looks fine about the email sending process, but I face a problem when I want to answer my user's email.
It seems that the email address that sends the email from my website is mine, configured via SMTP -> I'm fine with that.
I defined for both setFrom and addReplyTo methods user's email address as parameter, in order to be able to answer to his email from Gmail, and that my answer is sent to the email address provided.
However, when I click on "Reply" on Gmail, both user and I receive my answer.
I guess I really missed something about that, and / or misunderstood the purpose of these methods above.
I tried to place addReplyTo above setFrom as mentioned there, but looks like it doesn't change anything.
I'm kinda stuck about what else I can do, I only use PHP for 4 months now, and some things are still missing, especially about this issue.
//class Mail
public function sendMail ()
{
//Instantiation and passing "true" enables exceptions
$mail = new PHPMailer(true);
$msg = utf8_encode(wordwrap($this->message, 70, "\r\n"));
try {
//Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
//Recipients
//Jon Doe <[email protected](?)>
$mail->setFrom($this->mail, $this->first_name . ' ' . $this->last_name);
//User's email address
$mail->addReplyTo($this->mail);
$mail->addAddress('[email protected]');
// Content
$mail->isHTML(true);
//[email protected] : Jon Doe
$mail->Subject = '[email protected] : ' . $this->first_name . ' ' . $this->last_name;
$mail->Body = $msg;
$mail->AltBody = $msg;
$mail->send();
} catch (Exception $e) {
//False need for my contact.php webpage if email cannot be sent
if (!empty($e->getMessage())) {
$_POST['success'] = false;
}
}
}
//contact.php
if (!empty($_POST['last_name']) && !empty($_POST['first_name']) && !empty($_POST['mail']) && !empty($_POST['message']) && isset($_POST['g-recaptcha-response'])) {
$first_name = htmlentities($_POST['first_name']);
$last_name = htmlentities($_POST['last_name']);
$mail = htmlentities($_POST['mail']);
$message = htmlentities($_POST['message']);
$contact = new Contact($first_name, $last_name, $mail, $message);
//Checking if everything's fine about form submission
if ($contact->isBool()) {
$mail = new Mail($contact);
$mail->sendMail();
//If something's wrong with the mailing process
if (isset($_POST['success'])) {
//Just some text to display to inform the user
$error_email['email_sent'] = "Foo";
} else {
//Just some text to display to inform the user
$success = "Bar";
}
} else {
$errors = $contact->getErrors();
}
}
Here's also a screen shot from my Gmail account about mail informations:
I'd like to reply to user's email from my Gmail account, and wants him to be the only one to receive my reply. Any suggestion is welcome !
EDIT:
After many tries today, it looks like I'm the only one who receive my answer when I click on 'Reply' button on Gmail. User doesn't receive anything...