繁体   English   中英

如何在 PHP Mailer 中更改电子邮件发件人电子邮件

[英]How to change email sender email in PHP Mailer

   Currentlt it shows the mail on which phpmailer SMTP is registered.

    $email='abc@email.com';
    $subjectRsc="Any";
    $message='Welcome';
    phpmail($email, $subjectRsc, $message);

My phpmailer function: 

 $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->SMTPDebug = 0;
    $mail->SMTPAuth = true;
    $mail->Debugoutput = 'html';
    $mail->Host = 'smptp';
    $mail->Port = 465; // or 587
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->SMTPAuth = true;
    $mail->Username = PHP_MAILER_EMAIL;
    $mail->Password = PHP_MAILER_PASSWORD;
    $mail->AddReplyTo(REPLY_EMAIL, 'ABC');
    $mail->SetFrom(FROM_EMAIL, 'ABC');
    $mail->Subject = $subject;
    $address = $to;
    $mail->AddAddress($address);
    $mail->MsgHTML($message);
    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        return true;
    }

这就是我向用户发送邮件的方式,我希望显示我网站的特定邮件,而不是在注册 smtp 服务器的邮件中显示。

你应该试试这个:

   $mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Debugoutput = 'html';
$mail->Host = 'smptp';
$mail->Port = 465; // or 587
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->SMTPAuth = true;
$mail->Username = PHP_MAILER_EMAIL;
$mail->Password = PHP_MAILER_PASSWORD;
$mail->addReplyTo('myemail@example.com', 'ABC'); //<-- this is the line i changed
$mail->From= "myemail@example.com";  //<-- this is the line i changed
$mail->Subject = $subject;
$address = $to;
$mail->AddAddress($address);
$mail->MsgHTML($message);
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    return true;
}

根据 phpmailer 文档,这是添加发件人电子邮件的字段。

please try using this code  :

<?php

require_once "vendor/autoload.php";

//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";

//To address and name
$mail->addAddress("test@gmail.com", "Test");
$mail->addAddress("test1@gmail.com"); 

//Address to which recipient will reply

//if you want to add CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

?>

请尝试使用此代码:

<?php

$to = "test@gmail.com";
     $subject = "This is subject";

     $message = "<b>This is HTML message.</b>";
     $message .= "<h1>This is headline.</h1>";

     $header = "From:test1@gmail.com \r\n";
   $header .= "Cc:test2@gmail \r\n";
     $header .= "MIME-Version: 1.0\r\n";
     $header .= "Content-type: text/html\r\n";

     $retval = mail ($to,$subject,$message,$header);

     if( $retval == true ) {
        echo "Message sent successfully...";
     }else {
        echo "Message could not be sent...";
     }

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM