简体   繁体   English

通过php和标头发送邮件?

[英]Sending mail via php and from headers?

When I send mail from my php script I send it like so 当我从php脚本发送邮件时,我像这样发送邮件

$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 通过web87.extendcp.co.uk noreply@example.com

Is there a way I can stop the via bit from showing? 有什么方法可以阻止via位显示吗?

The only solution would be to use your own SMTP server, or at least another one... If your provider allows that. 唯一的解决方案是使用您自己的SMTP服务器,或者至少使用另一台SMTP服务器...如果提供商允许的话。

It is your provider's web server which modifies the From: line here. 是提供商的Web服务器在此处修改“ From:行。

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: 尽管在这里fge的答案很可能是正确的答案,但是如果标头中有一个“友好的”名称,则服务器的邮件服务总是有可能不会添加它:

From: No Reply <noreply@example.com>

...instead of just: ...而不仅仅是:

From: noreply@example.com

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

Try using the IMAP-method from PHP 尝试从PHP使用IMAP方法

First connect with the GMail imap-server: http://www.php.net/manual/en/function.imap-open.php (Make sure you're using SSL/TLS) 首先连接GMail imap服务器: http : //www.php.net/manual/zh/function.imap-open.php (确保您使用的是SSL / TLS)

Then send the message with imap_mail(): http://www.php.net/manual/en/function.imap-mail.php 然后使用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 ;) 希望这可以帮助 ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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