在共享主机上签名PHP邮件



我使用共享主机计划,当我用PHP发送电子邮件时,电子邮件客户端(如Gmail)将在我的from字段中添加一点via位,其中包含主机的域名。

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

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);

你可以试试这个,你需要从这里下载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!
    }
    ?>

默认邮件功能取决于您的服务器设置,并且在接收方看来很少像普通邮件。您应该使用一个库SwitfMailer或pear MAIL,它们可以通过SMTP通过您自己的邮件服务器发送邮件。您可以使用您的普通电子邮件帐户,也可以为您的web服务设置一个新帐户。

最新更新