Search code examples
phpemailcodeigniter-2phpmailercontact-form

Codeigniter PHP Mailer, Sender Info


I'm using Codeigniter PHP Mailer which is hosted here: https://github.com/ivantcholakov/codeigniter-phpmailer/ and with gmail smtp it works flawless. However,using it for a standard contact form, when visitors use that contact form and send us an email, they basically send mails from our mail address to our another mail addess. When they open their own email address, they wont be seeing what they sent in their own sent items. What I want to do is (maybe without using smtp settings) show the visitors own mail adress (the one I'm asking as an input on contact form) as the FROM part of the email I receive from my contact form. So that, in case I want to reply the mail, hitting the reply button would be enough. İnstead of doing coding tricks and showing their email somewhere I could copy/paste and send new email.


Solution

  • Don't do that. It's effectively forging the from address and will fail SPF checks. Instead, use your own address as the From address, and add the submitted address as a reply-to address. In PHPMailer:

    $mail->From = 'youraddress@example.com';
    $mail->addReplyTo($POST['emailfrom']);