在共享主机上签署PHP电子邮件

时间:2013-03-12 03:51:08

标签: digital-signature php dkim spf

我正在使用共享主机方案,当我使用PHP发送电子邮件时,电子邮件客户端(例如Gmail)会在我的via字段中添加一点from位主持人的域名在那里。

所以我的电子邮件只是来自我的域名,而不是我的电子邮件:

From: me@mydomain.com

它来自两个领域:

From: me@mydomain.com via host13.myhost.com

显然,这对接收电子邮件的人来说很困惑,而且品牌推广很差。由于我在共享主机方案中,我认为我不太可能访问PHP的配置设置或其用于邮件的任何设置。我可以对我的PHP电子邮件进行数字签名,还是在共享主机上不可能?

以下是我现在正在做的事情:

$header = "From: me@mydomain.com";
mail("you@yourdomain.com", "subject", "body", $header);

2 个答案:

答案 0 :(得分:1)

你可以尝试这个,你需要从Here下载PHP Mailer类,你的代码将是这样的:

 <?php
include "PHP MAILER CLASS";
    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
    $mail->IsSMTP(); // telling the class to use SMTP
    try {
        //$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
        $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
        $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
        $mail->Username   = "example@gmail.com";  // GMAIL username
        $mail->Password   = "password";            // GMAIL password
        $mail->AddAddress("Reciever Email", "Reciever Name");
        $mail->SetFrom('Sender Email', 'Sender Name');
        $mail->Subject = "Subject";
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
        $mail->MsgHTML("Message Body");
        $mail->Send();
    } catch (phpmailerException $e) {
        $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
        $e->getMessage(); //Boring error messages from anything else!
    }
    ?>

答案 1 :(得分:0)

默认邮件功能受服务器设置的限制,很少看起来像普通邮件到收件人。您应该使用SwitfMailerpear MAIL库,它可以通过SMTP通过您自己的邮件服务器发送邮件。您可以使用普通电子邮件帐户或为您的Web服务设置一个新帐户。

相关问题