电子邮件设置发送电子邮件在PHP通过自定义域在gmail


Email settings for sending email in PHP through custom domain on gmail

我在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 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());
   }
}

您可以使用变量和传递电子邮件,主题,消息等