Mailer function error - php

SMTP -> ERROR: DATA not accepted from server: 550 This message was classified as SPAM and may not be delivered
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.cc.com";
$mail->SMTPAuth = true;
$mail->Username = "info#cc.com";
$mail->Password = "cc";
$mail->From = "cc.com"." <info#cc.com>";
$mail->AddReplyTo("cc1#gmail.com");
$mail->FromName = "info#cc.com";
$mail->AddAddress($climail);
$mail->AddCC("cc1#gmail.com");
$mail->Sender="info#cc.com";
$mail->IsHTML(true);
$mail->WordWrap = 70;
$mail->Subject = $sub;
echo $meegate;
$mail->Body=$meegate;
$mail->SMTPDebug = 1;
$mail->Send();
Error occurring while sending mail.. mail not sent..

You need to set SMTP host and also the port I guess which is 465:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "info#gmail.com";
$mail->Password = "cc";
$mail->From = "gmail.com"." <info#gmail.com>";
$mail->AddReplyTo("cc1#gmail.com");
$mail->FromName = "info#gmail.com";
$mail->AddAddress($climail);
$mail->AddCC("cc1#gmail.com");
$mail->Sender="info#gmail.com";
$mail->IsHTML(true);
$mail->WordWrap = 70;
$mail->Subject = $sub;
echo $meegate;
$mail->Body=$meegate;
$mail->SMTPDebug = 1;
$mail->Send();

Related

Send two email ids in CC

I am obtaining two email id's from database by a query. Both stored in a single variable. I want to send email to these two addresses by PHPMailer keeping them in cc. Currently only one email is being selected and passed in cc. Can I know where am I going wrong. My code here,
$get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
$user_email_cc='';
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc=$get_data_cc['email'];
}
$mail = new PHPMailer();
$subject = "Mail";
$content ="XYZ";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port = 465;
$mail->Username = "xyz#xyz.com"; // Changed username and password from
$mail->Password = "xyz";
$mail->Host = "ssl://smtp.xyz.com";
$mail->Mailer = "smtp";
$mail->SetFrom("xyz#xyz.com", "XYZ");
$mail->AddAddress(abc#abc.com);
$mail->AddCC($user_email_cc);
$mail->Subject = $subject;
$mail->WordWrap = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);
if(!$mail->Send())
echo "Problem sending mail.";
else
echo "Mail Sent";
use this code
$mail->AddCC('person1#domain.com', 'Person One');
$mail->AddCC('person2#domain.com', 'Person Two');
use $user_email_cc as array then it will store you both email a 0 and 1 position
$user_email_cc=array();
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc[] =$get_data_cc['email'];
}
New Code
$get_cc_email_id_sql=mysql_query("select * from tbl_name where column_name IN(13,5)");
$user_email_cc=array();
while ($get_data_cc=mysql_fetch_array($get_cc_email_id_sql))
{
$user_email_cc[] =$get_data_cc['email'];
}
$mail = new PHPMailer();
$subject = "Mail";
$content ="XYZ";
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "ssl";
$mail->Debugoutput = 'html';
$mail->Port = 465;
$mail->Username = "xyz#xyz.com"; // Changed username and password from
$mail->Password = "xyz";
$mail->Host = "ssl://smtp.xyz.com";
$mail->Mailer = "smtp";
$mail->SetFrom("xyz#xyz.com", "XYZ");
foreach($user_email_cc as $email_cc){
$mail->AddCC($email_cc);
}
$mail->AddAddress(abc#abc.com);
$mail->Subject = $subject;
$mail->WordWrap = 80;
$mail->MsgHTML($content);
$mail->IsHTML(true);
if(!$mail->Send())
echo "Problem sending mail.";
else
echo "Mail Sent";
Can you call $mail->AddCC(...) multiple times, just like $mail->AddAddress(...)?

Error while sending email using 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;
}

While sending mail getting following error

<?php
require('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = "akilesh1111#gmail.com";
$mail->Password = "*********";
$mail->Host = "smtp.gmail.com";
$mail->Mailer = "smtp";
$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
$mail->AddReplyTo($_POST["userEmail"], $_POST["userName"]);
$mail->AddAddress("akilesh1111#gmail.com");
$mail->Subject = $_POST["subject"];
$mail->WordWrap = 80;
$mail->MsgHTML($_POST["content"]);
if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
}
$mail->IsHTML(true);
if(!$mail->Send()) {
echo "<p class='error'>Problem in Sending Mail.</p>";
} else {
echo "<p class='success'>Contact Mail Sent.</p>";
}
?>
This code is working fine in localhost
When uploading to server then it shows below error
SMTP Error: Could not authenticate. Problem in Sending Mail.

Username and Password not accepted

I'm trying to send a email using gmail's smtp (see below code) but I'm getting "Username and Password not accepted" error.
I've tried:
this link
allow less secure apps
ssl is enabled
enable imap/pop on gmail's settings
a different login
none of them works.
Here's the PHP code:
function sendEmail($from, $fromName, $msg)
{
$mail = new PHPMailer();
$mail->SMTPDebug = 4; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$mail->IsSMTP();
//$mail->Host = 'tls://smtp.gmail.com:587';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; //465
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = 'xxxx#gmail.com';
$mail->Password = 'yyyyyyy';
$mail->From = $from;
$mail->FromName = $fromName;
$mail->AddAddress('foo#gmail.com', ' ');
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Priority = 1;
$mail->Timeout = 60;
$mail->SMTPKeepAlive = true;
$mail->Subject = "subject here";
$mail->Body = $msg;
$mail->AltBody = 'testing..';
$ok = $mail->Send();
$mail->ClearAllRecipients();
$mail->ClearAttachments();
return $ok;
}
Update: Here's the full error message (with DebugMode = 4)
After testing I got this to work by changing the host to include the tls prefix.
function sendEmail($from, $fromName, $msg)
{
$mail = new PHPMailer();
$mail->SMTPDebug = 4;
$mail->WordWrap = 900;
$mail->IsSMTP();
//$mail->Host = 'tls://smtp.gmail.com:587';
$mail->Host = "tls://smtp.gmail.com";
$mail->Port = 587; //465
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = 'xxxx#gmail.com';
$mail->Password = 'yyyyyyy';
// Define o remetente
$mail->From = $from;
$mail->FromName = $fromName;
$mail->AddAddress('foo#gmail.com', ' ');
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Priority = 1;
$mail->Timeout = 60;
$mail->SMTPKeepAlive = true;
$mail->Subject = "subject here";
$mail->Body = $msg;
$mail->AltBody = 'testing..';
$ok = $mail->Send();
$mail->ClearAllRecipients();
$mail->ClearAttachments();
return $ok;
}

PhpMailer Authentication Error

I'm trying to configure email by using phpmailer and smtp but Authentication error appears.
Code below
include_once("phpmailer.php");
$mail = new PHPMailer();
$tarih = date("d.m.Y - H:i:s");
$mail->IsSMTP();
$mail->Host = "mail.golcukdh.gov.tr";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";
$mail->IsHTML(true);
$mail->From = "email";
$mail->AddAddress("email");
$mail->Subject = "subject";
$mail->Body = "Body Part";
$mail->Send()
?>
I tried to configure this by using asp.net with these authentication information and it was successfull. But I want to use php, what is wrong ?

Categories