简体   繁体   中英

PHPMailer + Postfix in a contact form: how to prevent being marked as spam when 'spoofing' user email

This is my situation:

I'm using a combination of PHPMailer and Postfix to get info from a contact form into a mailbox. I want to make it seem as if emails that arrive from the contact form are sent from the user submitting the data (and not from root@domain.com).

The way I solve this now, is by setting the From email and name, like so:

$m->setFrom($email, $name);

The issue that arises, is the following: because of setting the From email, my email provider (zoho) sees it as a spam message (I assume because I'm technically spoofing an email address), and it thus lands in the spam folder.

Is there a way to make it land in my inbox? Is there some way that I can whitelist the 'spoofing' sender (ie my server)?

I realise this could be done by leaving the From email field alone, and using $m->addReplyTo . But I won't be the only one using the email account, and I want to avoid any confusion. What I mean is, if someone sees an email coming in, and they a specific name, but then an email address that doesn't correspond with that name, they might be confused, or make errors in replying or sending new emails to that person (they'd actually just reply to the server). So that's a solution that's not very feasible to me.

This is the full code for the email setup:

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

$m = new PHPMailer;
$m->isSendmail();

$m->setFrom($email, $name);
$m->addAddress('my@inbox.com');

$m->Subject = $subject;
$m->Body = $message;

Nope, you can't forge from addresses and expect it to work. The right way is to put your own address in the from address, and the submitter's address in a reply-to. You can avoid visual confusion by putting the submitter's name along with the from address. This way it will look like it's from the submitter, replies will go to the right place, and you're not forging anything.

$m->setFrom('my@inbox.com', $name);
$m->addAddress('my@inbox.com');
$m->addReplyTo($email);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM