【发布时间】:2016-03-18 01:14:42
【问题描述】:
I can not send mail using the PHPMailer lib. My site is hosted on dreamhost,
使用 SMTP gmail,我可以更正确地发送到主机提供的配置,唯一的回报是: SMTP 错误:无法连接到服务器:php_network_getaddresses:getaddrinfo 失败:名称或服务未知(0) SMTP 连接()失败。 我的代码:
<?php
date_default_timezone_set('Etc/UTC');
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = trim(stripslashes($_POST['name']));
$from = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$message = trim(stripslashes($_POST['message']));
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'mail.example.com.br';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'e-mail@example.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Debugoutput = 'html';
$mail->isHTML(true);
$mail->setFrom($from, $name);
$mail->addReplyTo($from, $name);
$mail->addAddress('email@example.com');
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
`
【问题讨论】:
标签: phpmailer sendmail dreamhost