遇到错误,无法使用PHP mail()发送电子邮件。您的服务器可能未配置为使用此方法发送邮件
我正在尝试通过Gmail SMTP使用CodeIgniter发送电子邮件,但该功能不起作用。它在本地主机上显示此错误遇到错误,无法使用PHP mail()发送电子邮件。您的服务器可能未配置为使用此方法发送邮件,php,codeigniter,email,smtp,gmail,Php,Codeigniter,Email,Smtp,Gmail,我正在尝试通过Gmail SMTP使用CodeIgniter发送电子邮件,但该功能不起作用。它在本地主机上显示此错误 An Error Was Encountered Unable to send email using PHP mail(). Your server might not be configured to send mail using this method. 这里是我的电子邮件功能 $config = Array( 'protocol' => 'sm
An Error Was Encountered Unable to send email using PHP mail().
Your server might not be configured to send mail using this method.
这里是我的电子邮件功能
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '******@gmail.com', // change it to yours
'smtp_pass' => '**********', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = 'Test';
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('*********@gmail.com'); // change it to yours
$this->email->to('test@gmail.com');// change it to yours
$this->email->subject('Resume from JobsBuddy for your Job posting');
$this->email->message($message);
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
使用PHP邮件程序或SWIFT邮件程序
现在这里是PHPMAILER
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
//$mail->Host = gethostbyname('smtp.gmail.com');
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'sender@gmail.com'; //SMTP username
$mail->Password = 'sender-password'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('receiver1@gmail.com', 'Mailer');
$mail->addAddress('receiver2@gmail.com', 'Dylan');
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
试一试{
//服务器设置
$mail->SMTPDebug=SMTP::DEBUG_SERVER;//启用详细调试输出
$mail->isSMTP();//使用SMTP发送
$mail->Host='smtp.gmail.com';//设置要通过的smtp服务器
//$mail->Host=gethostbyname('smtp.gmail.com');
$mail->SMTPAuth=true;//启用SMTP身份验证
$mail->Username=sender@gmail.com“;//SMTP用户名
$mail->Password='sender Password';//SMTP密码
$mail->SMTPSecure=PHPMailer::ENCRYPTION\u STARTTLS;//启用TLS加密;`PHPMailer::ENCRYPTION\u SMTPS`鼓励//连接到的TCP端口,将465用于上面的`PHPMailer::ENCRYPTION\u SMTPS`
$mail->Port=587;//要连接的TCP端口,请将465用于上面的'PHPMailer::ENCRYPTION_SMTPS'
//接受者
$mail->setFrom('receiver1@gmail.com","梅勒",;
$mail->addAddress('receiver2@gmail.com","迪伦",;
//内容
$mail->isHTML(true);//将电子邮件格式设置为HTML
$mail->Subject='主题在这里';
$mail->Body='这是以粗体显示的HTML邮件正文!';
$mail->AltBody='这是非HTML邮件客户端的纯文本正文';
$mail->send();
回音“消息已发送”;
}捕获(例外$e){
echo“无法发送邮件。邮件程序错误:{$mail->ErrorInfo}”;
}
您可以使用composer安装这些惊人的libarries大多数主机管理员,阻止
mail()
功能,您可以尝试类似smtp
@AKiani的功能,但我必须在不同的Codeigniter应用程序上尝试相同的代码。它工作正常吗?