phpMailer does not send email - php

I have a problem with phpMailer. When I send the form, it returns this error:
SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed.
Here is my PHP code
$Mail = new PHPMailer();
$body = "Nome: <strong>".$nome."</strong><br>
Email: <strong>".$email."</strong><br>
Txt: <strong>".$txt."</strong><br>";
echo "$body";
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 1; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "ssl"; //Secure conection
$Mail->Port = 465; // set the SMTP port
$Mail->Username = 'email#gmail.com'; // SMTP account username
$Mail->Password = 'password'; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'email#gmail.com';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( 'email#gmail.com' ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = $txt;
$Mail->AltBody = "Nome: <strong>".$nome."</strong><br>
Email: <strong>".$email."</strong><br>
Txt: <strong>".$txt."</strong><br>";;
$Mail->Send();
$Mail->SmtpClose();
if ( $Mail->IsError() ) {
echo "ERROR<br /><br />".$Mail->ErrorInfo."<br /><br />";
}
else {
echo "OK<br /><br />";
}
I tried hosting Linux from Register.it, this is the URL dmatermoidraulica.simply-webspace.it

Related

I recently trying to use mail system but It doesn't work like before

I've once successfully build up my mailing system, but at that time I didn't understand what happen inside of it.
Now, I'm re-building same system, using PHPMailer, and now Gateway Timeout error happens. Please help me to fix my code down here.. What I did is just copy the example and put my account and password.
$Mail = new PHPMailer;
$Mail->SMTPDebug = 2;
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port
$Mail->Username = 'myid#gmail.com'; // SMTP account username
$Mail->Password = 'mypassword'; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'SUB';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'gatesplan#gmail.com';
$Mail->FromName = 'FROM NAME';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress($email); // To:
$Mail->isHTML(TRUE);
$Mail->Body = "Hi";
$Mail->AltBody = "Hi";
$Mail->Send();
$Mail->SmtpClose();

php mailer could not send email

I am trying to send an email from localhost with PHP. Here is my code:
<?php
// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
require_once('class.phpmailer.php');
require 'PHPMailerAutoload.php';
require 'class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost"; // specify main and backup server
$mail->SMTPAuth = false; // turn on SMTP authentication
$mail->Username = "TTTTTT#gmail.com"; // SMTP username
$mail->Password = ""; // SMTP password
$mail->Port = 25;
$mail->SMTPSecure = '';
$mail->From = $email;
$mail->AddAddress("bradm#inmotiontesting.com", "Brad Markle");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
When I run this code, it shows, "message has been sent" but it does not actually send the message. What is my problem?
change this code you have:
$mail->Username = "TTTTTT#gmail.com"; // SMTP username
$mail->Password = ""; // SMTP password
$mail->Port = 25;
$mail->SMTPSecure = '';
to this:
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
In addition to what Lelio Faieta posted, enable less secure apps in gmail
and to prevent your mail going to your spam
change
$mail->From = $email;
to your email and you can put $email in body of your message

Phpmailer working fine in localhost But not in server

date_default_timezone_set('Asia/Dubai');
include("classes/class.phpmailer.php");
$mail = new PHPMailer();
$body = "this is <strong>testing</strong> mail ". date('Y-m-d H:i:s');
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = 'my#email.com';
$mail->Password = '*******';
$mail->SetFrom('my#email.com', 'First Last');
$mail->AddReplyTo('my#email.com','First Last');
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "to#email.com"; // add your address here
$mail->AddAddress($address, "Gmail Test");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I have script like this.Its working fine with localhost but when i moving to windows or linux servers it won't work.I want to work on both windows and linux servers.What should i do?
Error like this:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
try using this :
require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug = 2; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port
$Mail->Username = 'MyGmail#gmail.com'; // SMTP account username
$Mail->Password = 'MyGmailPassword'; // SMTP account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'MyGmail#gmail.com';
$Mail->FromName = 'GMail Test';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->AddAddress( $ToEmail ); // To:
$Mail->isHTML( TRUE );
$Mail->Body = $MessageHTML;
$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();
if ( $Mail->IsError() ) {
echo "ERROR<br /><br />";
}
else {
echo "OK<br /><br />";
}
What version of PHPMailer you are using ? if you are using old version try with
$mail->Port = 587;
try to update PHPMailer version that will solve i hope !!!

PHP mailer sending email SMTP with wamp error (10061)

I am trying to send email/SMTP with PHP from my localhost with WAMP
but it's giving me the following error:
SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.
(10061)
here is my code:
require_once("./PHPMailer_5.2.4/class.phpmailer.php");
// The message
$message = "hello there!";
$mail = new PHPMailer();
$mail->IsSMTP();; // send via SMTP
$mail->Mailer = 'smtp';
$mail->SMTPDebug=4;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
//$mail->Port = 465;
// $mail->SMTPSecure = 'ssl';
// or try these settings (worked on XAMPP and WAMP):
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = "myemailu#gmail.com"; // SMTP username
$mail->Password = "mypass****"; // SMTP password
$webmaster_email = "myemail#doamin.com"; //Reply to this email ID
$email="ohermail#yahoo.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}

PHPMailer - make the sender mail variable

I'm using php mailer and i cant specify the sender mail , i want to be a variable every one type his email to be here , but it cant be done i must type my email and my password , so anyone know how it can be done
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "usermail"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->addReply=$_POST['email'] ;
$mail->addAddress=$_POST['email'];
$mail->Subject=$_POST['subject'];
$mail->Body=$_POST['message'] .$_POST['email'];
$mail->Sender=$_POST['email'];
try this code
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email#gmail.com";
$mail->Password = "password";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email#gmail.com");
#$mail->Send()
Go through this link -> Own-Email-System-using-SMTP-and-PHPMailer
OR,
Please elaborate your issues so that i can help you properly .
NOTE:If "Less secure app access" is turned off for your Gmail account, you have to turn it on. => Click Here To see . Is it ON or OFF
<?php
require_once 'vendor/autoload.php';
$mail = new PHPMailer\PHPMailer\PHPMailer;
//Enable SMTP debug mode
$mail->SMTPDebug = 0;
//set PHPMailer to use SMTP
$mail->isSMTP();
//set host name
$mail->Host = "smtp.gmail.com";
// set this true if SMTP host requires authentication to send mail
$mail->SMTPAuth = true;
//Provide username & password
$mail->Username = "YOUR_GMAIL_EMAIL_ID";
$mail->Password = "YOUR_GMAIL_PASSWORD";
$mail->SMTPSecure = "tls";
$mail->Port = 587;// Enter port number
$mail->ClearReplyTos();
$mail->addReplyTo("YOUR_GMAIL_EMAIL_ID", $_POST['name']); //$_POST['name'] => YOUR_GMAIL_NAME . You Can directly give "YOUR_GMAIL_NAME"
$mail->SetFrom("YOUR_GMAIL_EMAIL_ID", $_POST['name']);
$mail->addAddress($_POST["email"]); //TO WHOM U R SENDING MAIL
//Subject
$mail->isHTML(true);
$mail->Subject =" ".$_POST['subject']." ";
$body = "<html>
<head> </head>
<body>
".$_POST['message']." <br>
</body>
</html>";
$mail->MsgHTML($body);
if(!$mail->send()) {
$error_message = "Mailer Error : ". $mail->ErrorInfo;
echo $error_message;
} else {
echo "Email Sent Successfully";
}
?>

Categories