将其标记为重复之前,请先阅读。我已经尝试了一切!
我一直在尝试使用我以前使用过的SwiftMailer和PHPMailer从我的网站表单发送电子邮件。由于某种原因,最近几天,我没有让他们工作。每次,无论设置如何,我都会收到错误110-与smtp服务器的连接超时。我尝试从我的gmail帐户和1and1.com电子邮件帐户使用身份验证。我什至加了一张支票fsockopen
以及gmail,godaddy或1and1的smtp服务器都可以连接。而且我什至打过两次电话1and1,询问有关防火墙以及任何会阻止我的电子邮件的问题,他们说他们不知道可能是什么问题。我已经尝试了多个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 = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->From = '[email protected]';
$mail->addAddress('[email protected]');
$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('[email protected]')
->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('[email protected]'))
->setTo(array('[email protected]'))
->setBody($text, 'text/html');
// Send the message
$result = $mailer->send($message);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句