【问题标题】:PHPMailer from is showing as Root User来自的 PHPMailer 显示为 Root 用户
【发布时间】:2013-10-17 21:21:41
【问题描述】:

我正在使用 PHP Mailer 发送电子邮件,并且我正在使用 SMTP

这是我正在使用的代码:

$email = new PHPMailer();

            $email->IsSMTP(); // telling the class to use SMTP
            $email->Host       = "mail.integradigital.co.uk"; // SMTP server
            $email->SMTPDebug  = 2; // enables SMTP debug information (for testing)
                                                       // 1 = errors and messages
                                                       // 2 = messages only
            $email->SMTPAuth   = true;  // enable SMTP authentication
            $email->Host       = "mail.integradigital.co.uk"; // sets the SMTP server
            $email->Port       = 26;    // set the SMTP port for the GMAIL server
            $email->Username   = "sending@************.co.uk"; // SMTP account username
            $email->Password   = "********";        // SMTP account password

            $email->SetFrom($result["emailfrom"]);
            $email->FromName($result["emailfrom"]);

            $email->Subject   = $result["subject"];
            $email->Body      = $result["message"];

但它的发送和显示为来自 Root User - root@localhost

我知道我可以在 class.phpmailer.php 文件中更改它,但我希望能够在上面的代码中设置它

这可能吗?

【问题讨论】:

  • 您确定$result["emailfrom"] 设置了值吗?
  • 是的,它确实有价值

标签: php


【解决方案1】:

class.phpmailer.php 文件包含“var $FromName = 'Root User';”可以从“根用户”更改为“所需名称”的部分并完成您的工作。

【讨论】:

  • 没关系,我想如果你总是只有一个回复地址并且不想知道为什么事情不能正常运行。当某事运行不正常时,我倾向于想知道原因。我使用 PHPMailer 已经有一段时间了,这突然出现了。版本没有变化。显然,是我,但我很难把手指放在上面。
【解决方案2】:

将整个事情包装在一个 try catch 中。并在启用异常的情况下初始化 phpmailer

$email = new PHPMailer(true);

看起来使用了默认值。所以调用setFrom() 时出了点问题。它默默地失败了,因为它返回 false 而不启用异常。

try {
  // your mail code here
} catch (phpmailerException $e) {
  echo $e->getMessage();
}

并将电子邮件的设置和名称更改为:

$email->setFrom($result["emailfrom"], $result["emailfrom"]);

FromName 是属性而不是方法。

【讨论】:

  • 我希望能够让它来自一个名字而不是一个电子邮件地址
  • 我已经设法让它从一个电子邮件地址显示,但不是一个名字
  • 您知道电子邮件的工作原理吗?您还需要一个电子邮件地址.. :) $email->setFrom($result["emailfrom"], $result["emailfrom"]);
  • 那个没用,我试过 Name, email@domain.com 和 email@domain.com, Name
  • 课程就是这样运作的。您正在调用 FromName 作为方法。但它是一种财产。你真的应该使用setFrom
【解决方案3】:

用途:

$mail->setFrom('here email add of sender','here name of the sender');

第一个参数是电子邮件地址,如果它为空或不是有效的电子邮件地址,它将在使用 php mailer 发送邮件时显示为 ROOT 用户

【讨论】:

    【解决方案4】:

    好的,简而言之:

    $email->From = "email.address@gmail.com";
    $email->FromName = "Support Team";
    

    这对我有用。

    【讨论】:

    • Yes 也对我有用,这似乎更符合phpmailer.worxware.com/?pg=tutorial 上的基本示例,该示例不使用 getter 和 setter。 $mail->From = "from@example.com"; $mail-AddAddress("myfriend@example.net");
    • 方法错误。应该调用该方法,因为它提供了验证。
    【解决方案5】:

    当您收到 1.email 和 2.name 时,在您的表单中应该如下所示

    1. <input type="text" name="emailfrom">

    2. <input type="text" name="namefrom">

    在您的 php 代码中,它应该如下所示。

    $mail->setFrom($_POST['emailfrom'],$_POST['namefrom']);

    我在 infinityhost 上使用这些设置时遇到了同样的问题,希望对您有所帮助。

    $mail->Port = 587; // Which port to use, 587 is the default port for TLS security.
    $mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.```
    
    

    【讨论】:

      【解决方案6】:

      当我只向setFrom() 发送第一个参数时遇到了这个问题,name <email>

      setFrom() 不知道如何解析该结构。

      更改为两个单独的参数解决了这个问题。

      【讨论】:

        【解决方案7】:

        对于 PHPMailer 版本:5.1

        这对我有用:

            $mail->SetFrom('no-reply@example.com', 'Name From');
        

        希望它有效。

        【讨论】:

          【解决方案8】:

          编辑你的 phpmailer.php,改变:

          if($mail->Send()){
          

          到:

          if (mail($_POST["email"], 
                   $_POST["subject"],
                   $_POST["message"],
                   $_POST["sender"])) {
            echo'Email Sended';
          }
          
                   *HTML* 
          <form action="phpmailer.php" method="POST">
              <input type="hidden" name="sender" value="From: Support Team<Support@email.com>"/>
          </form>
          

          if ($mail-&gt;Send()) { 设置为 Auto root,如果您发送电子邮件和 From 未同时声明。

          【讨论】:

            猜你喜欢
            • 2022-01-05
            • 2019-10-05
            • 1970-01-01
            • 1970-01-01
            • 2020-08-04
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多