I have a project in which I have to send 100-200 mails to users but every mail has different token for each user. I have the email hosted on godaddy.
So I was looking to send email using phpmailer. Below is the script which I am testing but it keeps giving me this error -
SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'mailm/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
$mail->DKIM_domain = '127.0.0.1';
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtpout.secureserver.net";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "itsupport#mysite.ae";
//Password to use for SMTP authentication
$mail->Password = "Mypassword";
$mail->SMTPSecure = 'ssl';
//Set who the message is to be sent from
$mail->setFrom('itsupport#mysite.ae', 'IT Helpdesk');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('sgajara#gmail.com', 'IT Helpdesk');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//Replace the plain text body with one created manually
$mail->Body = 'This is a plain-text message body';
//Attach an image file
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
This script I have found on a blog.
Any alternatives to this are also welcomed, My purpose is to send 200 emails from my godaddy email account but every email has a separate token which is fetched from the database and then inserted in the mail body and sent to the user.
That is so simple:
You must focus on smtp host, port, ssl...
Change smtp host to: relay-hosting.secureserver.net
And DELETE port and ssl, thats all...
Do not use smtp port and smtp ssl true or false...
var fromAddress = "mailfrom#yourdomain";
// any address where the email will be sending
var toAddress = "mailto#yourdomain";
//Password of your mail address
const string fromPassword = "******";
// Passing the values and make a email formate to display
string subject = TextBox1.Text.ToString();
string body = "From: " + TextBox2.Text + "\n";
body += "Email: " + TextBox3.Text + "\n";
body += "Subject: " + TextBox4.Text + "\n";
body += "Message: \n" + TextBox5.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "relay-hosting.secureserver.net";
**//Warning Delete =>//smtp.Port = 80;**
**//Warning Delete =>//smtp.EnableSsl = false;**
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
You need to modify few configurations mentioned below. let me know if this works or not.
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->ssl = false;
$mail->authentication = false;
Related
Guys I have read many answers on this question but the problem still persists.
The PHPMailer is not sending emails giving the following error.
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Following is the code:
date_default_timezone_set('Etc/UTC');
require 'PHPMailer-master/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.domain.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port =25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
//Username to use for SMTP authentication
$mail->Username = "mail#mail.com";
//Password to use for SMTP authentication
$mail->Password = "password";
//Set who the message is to be sent from
$mail->setFrom("mail#mail.com","Contact Form");
//Set an alternative reply-to address
$mail->addReplyTo($_POST['user_mail'], $_POST['user_name']);
//Set who the message is to be sent to
$mail->addAddress("mail#mail.com", "Contact Form");
//Set the subject line
$mail->Subject = $_POST['subject'] . " - Contact Form";
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("Message from ". $_POST['user_name']." : <br/>".$_POST['message'] . "<br/> Contact Details : <br/> Email :" . $_POST['user_mail'] . "<br/> Contact Number : " . $_POST['user_number']);
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "<script>window.location.href='thankyou.html';</script>";
}
I tried to send a mail using smtp server in php mailer function.
This was the error am getting when I triggered this.
Am using the gmail mail server.
SMTP connect() failed.
require_once(TEMPLATEPATH . '/PHPMailer-master/PHPMailerAutoload.php');
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.gmail.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "xxxx";
//Password to use for SMTP authentication
$mail->Password = "xxxx";
//Set who the message is to be sent from
$mail->setFrom('xxxx', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('xxxxx', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('xxxx', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
$mail->msgHTML('test');
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
This is my code. Please suggest what is the mistake in my code or where to check smtp connection failed error.
Thanks in Advance.
Well, that's why it didn't work ,
Open your php.ini and search for this line ;extension=php_openssl.dll and remove the semi colon before it , save the file and restart your webserver. You will see your coding working after you do this change.
and set your host as follow:
$mail->Host = "ssl://smtp.gmail.com";
I recently setup phpmailer as my SMTP sending script to use for a website I've been working on and it's been nothing but a headache. My setup is IIS, and I'm currently using office365 to send out emails(although I have tried gmail and the results were no faster).I would appreciate any and all advice on how to speed this up, or if there's a way to post to a php file from javascript or php and then just let it work I could do that too. I'm trying to stay away from cron jobs if possible.
my script:
function sendMail($code, $email) {
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.office365.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "support#[domain redacted].com";
//Password to use for SMTP authentication
$mail->Password = "[password redacted]";
//enable TLS
$mail->SMTPSecure = 'tls';
//Set who the message is to be sent from
$mail->setFrom('support#[domain redacted].com', '[redacted]');
//Set an alternative reply-to address
$mail->addReplyTo('support#[domain redacted].com', '[redacted]');
//Set who the message is to be sent to
$mail->addAddress($email);
//Set the subject line
$mail->Subject = 'This is a test email from EdTester Support';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = "Hello there, This is your activation e-mail. Please go to: http://[domain redacted]/activate.php?code=". $code . "&email=" . $email;
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
I've been using PHPMailer for years and have been pretty happy with it, but now I'm trying to get a contact form working with an email address that is domain based but tied to Gmail via Google Apps. I.e. the MX record points to Google. I've added PHPMailer's Gmail example trying to get the setup to work, but at this point, I'm not connecting; I get this message:
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
Here's my form processor code:
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
// CUSTOM: collect data from our web form
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$tel = $_REQUEST['tel'];
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
//date_default_timezone_set('Etc/UTC');
require 'mailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "myemailaddress.com";
//Password to use for SMTP authentication
$mail->Password = "mypassword";
//Set who the message is to be sent from
//$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('myemailaddress', 'my name');
//Set the subject line
$mail->subject = $subject;
$mail->Body = "Name : $name\n\n"
. "Email : $email\n"
. "Telephone : $tel\n"
. "Message :\n\n $message\n"
. "";
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
To answer some questions in advance: yes, SSL rather than TLS is enabled in Gmail, and the MX record is changed at the host. I also did comment out some stuff, but as far as I can tell nothing that I need to get the form to actually send.
Beyond that, I don't even qualify as a hack with PHP; my primary skills are design, HTML and CSS, so I'm probably missing something obvious....
Thanks in advance.
I am not able to send email from any hosting containing link of my website https://www.gogglegator.com. Emails are working fine without this link and all other links in email are working fine.
When I tried phpmailer, I got error Mailer Error: SMTP Error: data not accepted.
Is there anybody who faced such issue ever and have possible troubleshooting steps? I am searching from three days but no success.
Thanks in advance for your time.
<?php
require_once('class.phpmailer.php');
include("class.smtp.php");
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
//Set the hostname of the mail server
$mail->Host = "smtp.mail.yahoo.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 465;
//Username to use for SMTP authentication
$mail->Username = "myaddress#yahoo.com";
//Password to use for SMTP authentication
$mail->Password = "mypass";
//Set who the message is to be sent from
$mail->setFrom('myaddress#yahoo.com', 'Test');
//Set an alternative reply-to address
$mail->addReplyTo('myaddress#yahoo.com', 'Test');
//Set who the message is to be sent to
$mail->addAddress('myaddress#yahoo.com');
//Set the subject line
$mail->Subject = "Test";
$mail->MsgHTML("https://www.gogglegator.com/");
if (!$mail->send()) {
$message = "Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Thank you for contacting us.";
}
echo $message; ?>