Error while sending email using php - php

SMTP -> ERROR: Failed to connect to server: An attempt was made to access a socket in a way forbidden by its access permissions. (10013) The following From address failed: info#gmail.com : Called Mail() without being connected
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "gmail.com";
$mail->Password = "password";
$mail->From = "info#gmail.com";
$mail->FromName = "name.com";
$mail->Subject = "Register";
$mail->MsgHTML($userMsg);
$mail->AddAddress("email address", "name");
//$mail->AddAddress($rowUser['user_email'], $rowUser['user_name']);
$mail->send();
$mail->ClearAllRecipients();

TLS is correct, you could try SSL, change port to 465. Check your credentials. Is on-screen Username "gmail.com"?
Try this:
$mail = new PHPMailer();
$mail->IsSMTP(); // enable SMTP
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "yourname#gmail.com";
$mail->Password = "yourpassword";
$mail->SetFrom("example#gmail.com");
$mail->Subject = $subject;
$mail->Body =$body;
$mail->AddAddress($email);
if(!$mail->Send())
{
return FALSE;
}

Related

Office365 smtp not always working with php mailer

I'm trying to use office365 smtp with phpmailer, it authenticates and it delivers sometime but sometimes it does. Not in inbox or spam. It works well with other smtp server. Here is my code:
$mail = new PHPMailer(true);
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
$mail->CharSet = "utf-8";
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = $host;
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
//Provide username and password
$mail->Username = $user;
$mail->Password = $pass;
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "STARTTLS";
//Set TCP port to connect to
$mail->Port = $port;
$mail->From = $from_email;
$mail->FromName = $from_name;
foreach($recipients as $recipients){
$mail->AddBcc($recipients);
}
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->msgHTML($message);

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting while in hosting

While running the PHPMailer in localhost mail will be sending but while hosting the PHPMailer shows the error as SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting. please help me.
here is my code
<?php
//include PHPMailerAutoload.php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'mail#gmail.com';
$mail->Password = 'password';
$mail->setFrom('mail#gmail.com', 'mail');
$mail->addAddress('mail#gmail.com');
$mail->Subject = 'SMTP email test';
$mail->Body = 'Thanks for commenting';
if ($mail->send())
echo "mail is sent";
else
echo $mail->ErrorInfo;
?>
Ok let's make it clearly :
Make sure your SMTP Port code is same with SMPT port in your host
Auth to your account is not wrong
Check phpmailer class are success to call like vardump or something else
Sample of my Code :
require(https://example.com/PHPMailerAutoload.php');
require(https://example.com/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'mail.example.com';
$mail->SMTPAuth = TRUE;
$mail->Username = 'customer_service#example.com';
$mail->Password = 'blablabla';
$mail->From = 'customer_service#example.com';
$mail->setFrom('customer_service#example.com', 'My Cool Website');
$mail->AddAddress('recipient#destination.com', 'Recipient Full Name');
$mail->WordWrap = 70;
$mail->Subject = 'PHP Mailer';
$mail->Body = 'Awesome';
$mail->IsHTML(TRUE);

Getting SMTP Error "Could not connect to SMTP host" on server but working on my localhost

I am using phpmailer with gmail smtp, and its working for "tls" on my local xampp, but when i moved my project on server mail could not send and gives error: SMTP Error: Could not connect to SMTP host.
My Code is:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Port = 587; // Or 587
$mail->Username = $admin_email;
$mail->Password = $admin_password;
$mail->SMTPSecure = 'ssl';
$mail->From = $admin_email;
// $mail->FromName= $from_name;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->addAddress($emailTo);
if (!$mail->send()){
echo "error";
}
What is wrong in my code?

While sending a email such errors occurs ...not working its live

SMTP -> ERROR: Failed to connect to server: An attempt was made to access a socket in a way forbidden by its access permissions. (10013)
The following From address failed: info#gmail.com : Called Mail() without being connected.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "name#gmail.com";
$mail->Password = "password";
$mail->From = "info#gmail.com";
$mail->FromName = "name.com";
$mail->Subject = "Register";
$mail->MsgHTML($userMsg);
$mail->AddAddress("useremail", "username");
$mail->send();
$mail->ClearAllRecipients();

PHPMailer With Yii

I am trying to send email using PHPMailer with Yii with no success. Here are my Settings:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "mymail#gmail.com";
$mail->Password = "************";
$mail->SMTPSecure = 'ssl'
Here is my Controller Function:
$mail->IsHTML(true);
$mail->From = Yii::app()->params['adminEmail'];
$mail->FromName = empty($_POST['EmailForm']["from_name"]) ? Yii::app()->params['emailFrom'] : $_POST['EmailForm']["from_name"];
$mail->Subject = $subject;
$mail->Body = nl2br($message) . $mail->Body;
$mail->AddAddress($to);
$mail->AddCC($cc);
$mail->send();
But When I try to send an email the following error pops up:
The following email address failed myemail#gmail.com. called mail()
without being connected.
Please help me solve this!
with smtp.gmail.com i think you should use this setting:
$mail->Port = 587;
$mail->SMTPSecure = 'tls';

Categories