我有以下用于发送电子邮件的代码。这在 MAMP 上运行良好;但不是在 LAMP 上。
$config = [
'crlf' => "\r\n",
'mailtype' => 'html',
'newline' => "\r\n",
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtpout.secureserver.net',
'smtp_pass' => 'password',
'smtp_port' => 465,
'smtp_user' => 'username',
'wordwrap' => true,
];
$this->load->library('email', $config);
// Send the email
$this->email->from('[email protected]', 'Email Name');
$this->email->to('[email protected]');
$this->email->subject('Subject');
$this->email->message('Message');
$this->email->set_newline("\r\n");
var_dump($this->email->send());
false
从 var_dump
调用返回。 OpenSSL 已安装。我检查了此实例的安全组设置,所有出站流量均已启用。
正如我之前建议的,我添加了一个在 Amazon EC2 上使用 PHPmailer 的示例。(工作/测试良好)
当您使用普通邮件 (aws) 时,您必须付费。阅读有关 Amazon Simple Email Service 的更多信息和如何在 EC2 上设置 SMTP
控制器
require_once('./phpmailer/class.phpmailer.php'); # Files attached below
require_once('./phpmailer/class.smtp.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "[email protected]";
$mail->Password = "password";
$to = ('[email protected]');
$subject = 'This is and test mail from PHPMailer';
$message = 'Hi';
$message .= 'this is an mail body';
$mail->SetFrom( '[email protected]' , 'Stack OverFlow' );
$mail->AddAddress( $to , 'Abdulla Nilam' );
$mail->Subject = $subject;
$mail->MsgHTML( $message );
$sendEmail = $mail->Send();
if( $sendEmail == true )
{
$this->session->set_flashdata('success', 'It was sent ....');
redirect('contact');
}
else
{
$this->session->set_flashdata('error', 'Nah :/ something wrong');
redirect('contact');
}