PHPMailer Error - multiple errors - php

Could not access file: http://localhost/k/d/filename.pdf
2014-07-28 16:20:10 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
(10060) SMTP connect() failed. Mailer Error: SMTP connect() failed.
I am trying to send an email. I'm using XAMPP and PHPMailer, and I have no idea what I'm doing wrong. I've looked up tons of similar issues, but I can't find my error.
require("PHPMailer/class.phpmailer.php");
require 'PHPMailer/class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "username#gmail.com";
$mail->Password = "password";
$webmaster_email = "username#gmail.com";
$email=$_POST['email'];
$name=$_POST['email'];
$mail->From = "username#gmail.com";
$mail->FromName = "User Name";
$mail->AddAddress($_POST['email'],$_POST['email']);
$mail->AddReplyTo("username#gmail.com","User Name");
$mail->WordWrap = 50;
$mail->AddAttachment($_POST['file']);
$mail->IsHTML(true);
$mail->Subject = "sent document";
$mail->Body = "Here is the document you requested. Thank you.";
$mail->AltBody = "Here is the document you requested from myITpc. Thank you.";
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
$_POST['email'] contains an email address, such as joe.shmo#hotmail.com and $_POST['file'] contains a local filepath, like http://localhost/folder/file.pdf.
Thanks!

Related

Not able to send smtp mail using php

I am trying to send SMTP email using my gmail account details through PHP but every time I try got an error. I am writing my code so you can see what is the problem.
PHP:
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "username";
$mail->Password = "password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "sender email";
$mail->FromName = "sender name";
$mail->addAddress("receiver email");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
and the error I am facing:
2016-08-12 00:22:02 Connection: opening to smtp.gmail.com:587,
timeout=300, options=array ( ) 2016-08-12 00:22:16 SMTP ERROR: Failed to
connect to server: Network is unreachable (101) 2016-08-12 00:22:16 SMTP
connect() failed. Mailer Error: SMTP connect() failed.
any help would be appreciated.
Thanks

PHPMailer in localhost showing an error Called Mail() without being connected. how can I fix it?

<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
// ---------- adjust these lines ---------------------------------------
$mail->Username = "mymail#gmail.com"; // your GMail user name
$mail->Password = "xxxxxxxxxx";
$mail->AddAddress("yourmail#yahoo.com"); // recipients email
$mail->FromName = "abc"; // readable name
$mail->Subject = "Sample Email";
$mail->Body = "Here is the message you want to send to your friend.";
//-----------------------------------------------------------------------
$mail->Host = "ssl://smtp.gmail.com"; // GMail
$mail->Port = 25;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
if(!$mail->Send())
echo "Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
Mailer Error: The following From address failed: mymail#gmail.com : Called Mail() without being connected.
How can I fix it??

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";
}

Sending mail in PHP using Hotmail smtp

I am trying to send mail in PHP using Hotmail Smtp. But I am getting error as below:
2014-03-13 06:59:01 CLIENT -> SERVER: EHLO site.com
2014-03-13 06:59:01 CLIENT -> SERVER: AUTH LOGIN
2014-03-13 06:59:01 SMTP ERROR: AUTH command failed: 504 5.3.3 AUTH mechanism LOGIN not available
2014-03-13 06:59:01 CLIENT -> SERVER: QUIT SMTP connect() failed. Mailer Error: SMTP connect() failed.
Please would anyone suggest me what I am doing wrong??
My code :
error_reporting(E_STRICT);
require_once('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer(); //Initialize a new PHPMailer object;
//$body = preg_replace("[\]",'',$body); //Replace unwanted characters of the content
$mail->CharSet ="ISO-8859-1";//Set the character set you need to specify
$mail->IsSMTP(); // Use SMTP service
$mail->SMTPDebug = 1; // Enable debugging for SMTP
// 1 = errors and messages
// 2 = messages only
$mail->From = 'abc#hotmail.com';
$mail->FromName = 'Name';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "SSL";
$mail->Host = 'smtp.live.com';
$mail->Port = '465';
$mail->Username = 'abc#hotmail.com'; //Username of your email account
$mail->Password = '***'; //Password of your email account
$mail->SetFrom('abc#hotmail.com', 'Name');
$mail->AddReplyTo('abc#hotmail.com','Name');
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional, comment out and test
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
//var_dump($body);
if(!$mail->Send()) {
//echo $body;
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo "Message sent successfully!";
}
Need help. thanks.
How would I solve this problem? Anyone's help would be appreciated.
Below works for me:
$mail = new PHPMailer();
$mail->SMTPSecure = 'tls';
$mail->Username = "mymail#hotmail.com";
$mail->Password = "mypassword";
$mail->AddAddress("mymail#hotmail.com");
$mail->FromName = "My Name";
$mail->Subject = "My Subject";
$mail->Body = "My Body";
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
$mail->Send();
Windows Live Mail uses port 587(TLS enabled) not the standard 465.
That said wht not just use your hosts local smtp server? That way you won't have to auth (or collect the senders password) and you can still set the senders address as their Hotmail.
$mail->SMTPSecure = "tls";

Sending mail with hotmail smtp in php

I am trying to send email through PHPMailer. And while sending it gives me error as
SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Mailer Error: SMTP connect() failed.
I really can't figure it out what's wrong. Is it the server configuration problem or code configuration problem. If anyone knows the answer please let me know.
Code below:
require_once('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer(); //Initialize a new PHPMailer object;
$body = eregi_replace("[\]",'',$body); //Replace unwanted characters of the content
$mail->CharSet ="ISO-8859-1";
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->From = 'email';
$mail->FromName = 'name';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = 'smtp.live.com';
$mail->Port = '465';
$mail->Username = 'email ';
$mail->Password = 'password';
$mail->SetFrom('email', 'who');
$mail->AddReplyTo('email','who');
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, '');
if(!$mail->Send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo "Message sent successfully!";
}

Categories