请在将此标记为重复之前阅读。我已经尝试了一切!
我一直在尝试使用之前使用的SwiftMailer和PHPMailer来从我的网站表单发送电子邮件。出于某种原因,在过去的几天里,我还没有让他们上班。每次,无论设置如何,我都会收到错误110 - 连接超时到smtp服务器。我尝试过使用我的gmail帐户和1and1.com电子邮件帐户进行身份验证。我甚至使用fsockopen
添加了一个支票,gad,godaddy和1and1的smtp服务器都可以连接到。而且我甚至两次打电话给1和1来询问防火墙以及任何会阻止我的电子邮件的事情,并且他们已经说他们不知道问题可能是什么。我已尝试在多个Stackoverflow问题上列出的所有内容,但无法解决此问题。有什么事情会阻止这种情况吗?我的网络连接(尝试过家庭和工作)可能吗?我很失落!我的PHPMailer和SwiftMailer代码将粘贴在下面。请记住,我尝试使用端口465 / ssl和端口587 / tls,但都没有工作。
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'inquiry@example.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'inquiry@example.com';
$mail->addAddress('example@gmail.com');
$mail->isHTML(true);
$checkconn = fsockopen($mail->Host, $mail->Port, $errno, $errstr, 5);
if($_GET['formName'] == 'join')
{
$text = 'Name: <b>' . $_POST['first_name_join']. " " .$_POST['last_name_join']. "</b>".
"<br>Phone: <b>".$_POST['phone_join']. "</b>".
"<br>Email: <b>".$_POST['email_join']. "</b>".
"<br>Date of Birth: <b>".$_POST['birth_month']. "/" .$_POST['birth_day']. "/" .$_POST['birth_day']. "</b>".
"<br>Message: <br><b>".$_POST['message_join']. "</b>";
}
else
{
$text = 'Name: <b>' . $_POST['full_name_sponsor']. "</b>".
"<br>Company/Organization: <b>" . $_POST['company_sponsor']. "</b>".
"<br>Phone: <b>".$_POST['phone_sponsor']. "</b>".
"<br>Email: <b>".$_POST['email_sponsor']. "</b>".
"<br>Message: <br><b>".$_POST['message_sponsor']. "</b>";
}
$mail->Subject = $_GET['formName'] == 'join' ? 'Join Inquiry' : 'Sponsorship Inquiry' ;
$mail->Body = $text;
if (!$checkconn)
{
echo "($errno) $errstr\n\n";
}
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
和
require_once 'swiftmailer/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.com', 587)
->setUsername('inquiry@example.com')
->setPassword('password');
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
if($_GET['formName'] == 'join')
{
$text = 'Name: <b>' . $_POST['first_name_join']. " " .$_POST['last_name_join']. "</b>".
"<br>Phone: <b>".$_POST['phone_join']. "</b>".
"<br>Email: <b>".$_POST['email_join']. "</b>".
"<br>Date of Birth: <b>".$_POST['birth_month']. "/" .$_POST['birth_day']. "/" .$_POST['birth_day']. "</b>".
"<br>Message: <br><b>".$_POST['message_join']. "</b>";
}
else
{
$text = 'Name: <b>' . $_POST['full_name_sponsor']. "</b>".
"<br>Company/Organization: <b>" . $_POST['company_sponsor']. "</b>".
"<br>Phone: <b>".$_POST['phone_sponsor']. "</b>".
"<br>Email: <b>".$_POST['email_sponsor']. "</b>".
"<br>Message: <br><b>".$_POST['message_sponsor']. "</b>";
}
// Create a message
$subject = $_GET['formName'] == 'join' ? 'Join Inquiry' : 'Sponsorship Inquiry' ;
$message = Swift_Message::newInstance($subject)
->setFrom(array('inquiry@example.com'))
->setTo(array('example@gmail.com'))
->setBody($text, 'text/html');
// Send the message
$result = $mailer->send($message);