duanpuchun5275 2014-01-08 20:19
浏览 5
已采纳

PHP MAILER:Root用户替换信息[关闭]

This event happens so randomly and I have no clue as to why. Information that appears looks like this.

From: Root User < root@localhost.mydomain.com >

Below is a snippet of what I wrote:

    $frtname = (!empty($_POST['frtname'])? mysql_real_escape_string($_POST['frtname']) :null);
    $lstname = (!empty($_POST['lstname'])? mysql_real_escape_string($_POST['lstname']) :null);
    $email   = (!empty($_POST['email'])? mysql_real_escape_string($_POST['email']) :null);



    $message=$body;

    $new_recipient = array(
          'user@email.com' => 'User Name',
          'user1@email.com' => 'User Name 1'
    );


    require_once ('phpMailer/class.phpmailer.php');
     try{ 
          $mail = new PHPMailer();
          $mail->SetLanguage("en",'phpMailer/language/');
          $mail->Priority              = 1;

          $mail->SetFrom(stripcslashes($email), stripcslashes($frtname." ".$lstname), true);
          $mail->AddReplyTo(stripcslashes($email), stripcslashes($frtname." ".$lstname)); 

          foreach($new_recipient as $email => $name){
               $email      = str_replace("'", "", $email);
               $name      = str_replace("'", "", $name);

               $mail->AddAddress($email, $name);
          }

          $mail->Subject = stripcslashes($subject);

          $mail->MsgHTML(stripcslashes($message));

          $mail->AltBody = 'This email is best view as HTML format.';


           if(!$mail->Send()) {
                echo "Mailer Error: " . $mail->ErrorInfo;
           } else {
                 echo "Message sent!";
                 $message="Your information was received, click ok to continue";
           }

           $mail->ClearAddresses();
           $mail->ClearAttachments();

      }catch(phpmailerException $e){
           echo $e->errorMessage();
           $message = "Your message was not sent. Please try again.";
      }catch(Exception $e){
           echo $e->getMessage();
           exit;
      }

I am already using a try and catch method here. Can anyone give an insight as to why this is happening? Do i give up on phpMailer?

  • 写回答

1条回答 默认 最新

  • dreamwind1985 2014-01-08 20:23
    关注

    Be sure and set the Sender property, as well as the From and FromName properties. Also, when you do that, make sure it's an email address for a valid domain, with an MX and SPF record.

    If the Sender property isn't set, sendmail will inject the header with the default info for the server, usually something like nobody@myserver.com or root@myserver.com

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条