在phpmailer上设置电子邮件

时间:2013-10-02 16:56:45

标签: php email gmail phpmailer

我正在使用PHPMailer发送电子邮件。效果很好,除了电子邮件的发件人地址显示为Me! [myuser@gmail.com]而不是Me! [myemail@comcast.net]。如何设置电子邮件的发件人电子邮件地址?

<?php
    require_once ('class.phpmailer.php');
    $email='myemail@comcast.net';


    $mail = new PHPMailer;

    $mail->isSMTP();                                      // Set mailer to use SMTP

    $mail->Host       = "smtp.gmail.com";
    $mail->Port       = 587;    //Maybe 465 instead? SSL only?
    $mail->Username   = "myusername";
    $mail->Password   = "mypassword";


    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

    $mail->From = $email;
    $mail->FromName = 'Me!';
    $mail->addAddress($email, 'Josh Adams');  // Add a recipient
    $mail->addReplyTo($email, 'Information');
    $mail->addCC($email);
    $mail->addBCC($email);

    $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
        exit;
    }

    echo 'Message has been sent';

1 个答案:

答案 0 :(得分:2)

Kristen很可能在评论中是正确的,但您可以尝试编辑class.phpmailer.php文件并更改其中的设置。

// The From email address for the message.
// @type string

   public $From = 'root@localhost';

// The From name of the message.
// @type string

   public $FromName = 'Root User';

// The Sender email (Return-Path) of the message.
// If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
// @type string

    public $Sender = '';