简体   繁体   中英

Sending mail via php and from headers?

When I send mail from my php script I send it like so

$to = $_POST['email'];
$subject = $_POST['username'] . ' - Validate your account at example.com!';
$message = 'http://www.example.com/activate?username=' . $_POST['username'] . '&code=' . $random;
$headers = 'From: noreply@example.com';

When the mail comes through to an email the from header shows like this,

noreply@example.com via web87.extendcp.co.uk

Is there a way I can stop the via bit from showing?

The only solution would be to use your own SMTP server, or at least another one... If your provider allows that.

It is your provider's web server which modifies the From: line here.

While fge's answer is most likely the correct one here, there's always a chance that your server's mail service won't add it if there's a "friendly" name in the header:

From: No Reply <noreply@example.com>

...instead of just:

From: noreply@example.com

是的,您需要对电子邮件实施DKIM签名 ,以便Gmail可以验证您的服务器是否有权发送该域的电子邮件。

Try using the IMAP-method from PHP

First connect with the GMail imap-server: http://www.php.net/manual/en/function.imap-open.php (Make sure you're using SSL/TLS)

Then send the message with imap_mail(): http://www.php.net/manual/en/function.imap-mail.php

$host="{imap.gmail.com:993/imap/ssl/novalidate-cert}";
$user=""; // Your GMail-account
$pass=""; // Your GMail-password
if ($mbox=imap_open($host, $user, $pass)) {
    // Connection Success
    $to = "";
    $subject = "";
    $headers = "";
    imap_mail ($to, $subject, $message, $headers)
} else {
    // Failed to connect
}

Hope this helps ;)

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