codeigniter 在运行Ubuntu的ec2示例上无法发送电子邮件

nr7wwzry  于 8个月前  发布在  其他
关注(0)|答案(1)|浏览(51)

我有以下代码,用于发送电子邮件。这在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());

falsevar_dump调用返回。OpenSSL已安装。我检查了此示例的安全组设置,所有出站流量都已启用。

ev7lccsx

ev7lccsx1#

正如我前面所建议的,我添加了一个在AmazonEC 2上使用PHPmailer的示例。(运行/测试良好)
当你使用普通邮件(aws)时,你必须付费。Read More about Amazon Simple Email ServiceHow to setup SMTP on EC2

控制器

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');
}

Files of PHPMailer

相关问题