【问题标题】:Email settings for sending email in PHP through custom domain on gmail通过 gmail 上的自定义域在 PHP 中发送电子邮件的电子邮件设置
【发布时间】:2015-09-26 06:55:15
【问题描述】:

我在 gmail 上为邮件设置了自定义域。

我在不同的托管服务提供商上托管了我的网站,我正在使用 CodeIgniter 和 PHP 通过我的帐户发送电子邮件。

启用通过我的 gmail 帐户发送邮件(从联系表)需要哪些设置? 我需要使用什么代码?

更新: 我尝试过的是以下内容: - 创建一个新的电子邮件帐户(@gmail.com,非自定义) - 启用两步验证 - 生成应用程序专用密码 - 用它来发送电子邮件 即使这样也行不通。

这是我正在使用的代码:

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'ssl://smtp.googlemail.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'samesenderaccount@gmail.com';                            // SMTP username
$mail->Password = 'appspecificpassword';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
$mail->Port = 465;   

$mail->From = 'samesenderaccount@gmail.com';
$mail->FromName = 'Mailer';
$mail->AddAddress('samesenderaccount@gmail.com', 'Info');  // Add a recipient
//$mail->AddAddress('ellen@example.com');               // Name is optional
$mail->AddReplyTo('other@gmail.com', 'From Try');
//$mail->AddCC('cc@example.com');
//$mail->AddBCC('bcc@example.com');

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

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body in bold!';

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

echo 'Message has been sent';
?>

【问题讨论】:

    标签: php email gmail


    【解决方案1】:

    您必须使用以下格式在 php codeigniter 中发送电子邮件。 您可能会从提供者那里找到要更改的值。

    public function sendMail()
    {
          $config = Array(
         'protocol' => 'smtp',
         'smtp_host' => 'ssl://smtp.googlemail.com',
         'smtp_port' => 465,
         'smtp_user' => 'axxx@gmail.com', // change it to yours
         'smtp_pass' => '*******', // change it to yours
         'mailtype' => 'html',
         'charset' => 'iso-8859-1',
         'wordwrap' => TRUE
        );
    
    
         $this->load->library('email', $config);
         $this->email->set_newline("\r\n");
         $this->email->from('xxx@gmail.com'); // change it to yours
         $this->email->to('yyy@gmail.com');// change it to yours
         $this->email->subject('Subject');// change it to yours
         $this->email->message('message');// change it to yours
    
         if($this->email->send())
        {
          //success message
        }
        else
       {
        show_error($this->email->print_debugger());
       }
    }
    

    您可以使用变量并传递电子邮件、主题、消息等。

    【讨论】:

    • 我正在使用自定义域。 gmail也不允许再发送这样的邮件了。
    猜你喜欢
    • 2012-01-07
    • 2023-03-19
    • 2016-11-03
    • 2012-03-22
    • 1970-01-01
    • 2016-09-26
    • 2011-06-01
    相关资源
    最近更新 更多