Reputation: 1838
Please read before marking this as a duplicate. I have tried everything!
I have been trying to use SwiftMailer and PHPMailer, both which I have use before, to send emails from my website form. For some reason, for the last few days, I haven't gotten them to work. Each time, no matter the settings, I get error 110 - Connection timeout to the smtp server. I have tried using authentication from my gmail account and 1and1.com email account. I have even added a check using fsockopen
and gmail, godaddy nor 1and1's smtp server can be connected to. And I've even called 1and1 twice to ask about firewalls and anything that would prevent my emails and they've said they don't know what the problem could be. I have tried everything listed on multiple Stackoverflow questions and cannot fix this. Is there anything going on that would prevent this? My internet connection (tried home and work) maybe? I'm very lost! My code for PHPMailer and SwiftMailer will be pasted below. Please remember that I have tried using port 465/ssl and port 587/tls and neither has worked.
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';
}
and
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);
Upvotes: 2
Views: 4718
Reputation: 278
Well it might a case where the ISP is Blocking the SMTP. And I know I am not giving a direct solution. It won't hurt to try other services to send your mail out thru API, thereby eliminating SMTP altogether.
I have good experiences with Mailgun and Mandrill . They both have extension documentation and PHP SDK for API and can also be used thru SMTP.
Best Wishes.
Upvotes: 1