Php Mailer Ending Up In Spam In Proudction - php

Here is my code below. But it keeps ending up in spam
I already added authentication and changed the setfrom address but it still ends up in spam
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = true;
// $mail->SMTPAutoTLS = true;
$mail->Username = '******'; // SMTP username
$mail->Password = "******";
$mail->Port = 25;
$mail->setFrom('info#canbeltech.com', 'Canbel Tech');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = 'Canbel Tech IMT Biometric Card Receipt';
$mail->Body = $body;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
exit;

Related

Send email via SMTP gmail using php

I got this error
Message could not be sent. Mailer Error: SMTP connect() failed.https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '*****';
$mail->Password = '*****';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SetFrom('*****', 'Innovatory');
$mail->AddAddress($f1_email);
$mail->isHTML(true);
$bodyContent = '<br><h3>From: '.$f1_fname.'</h3>';
$bodyContent .= '<b>Company Name: '.$f1_subject.'<br>Mobile: '.$f1_phone.'<br>Email: '.$f1_email.'</b><br><br><b>Service:</b> '.$f1_message;
$mail->Subject = 'Contact Email';
$mail->Body = $bodyContent;
$mail->mailer="smtp";
if(!$mail->send())
{
echo 'Message could not be sent. ';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
?>
<script>
alert('Mail has been sent.');
window.location.href='index.php';
</script>
<?php
}

send mail from local server using xampp in php

<?php
class EmailModel extends CI_Model{
public function email(){
require 'Email Files/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'Google account username';
$mail->Password = 'Google account Password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->addAddress('abc#gmail.com');
$mail->setFrom('abc#gmail.com');
$mail->Subject = 'Test';
$mail->Body = 'Testing';
if($mail->send()) {
echo 'Message has been sent';
} else {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
}
}
?>
I am using Github library for php email.
when I var_dump($mail) ; its showing all the data in the array.
now, this code is showing error: "SMTP connect() failed"
I also had this problem.Do the following steps
Go to myaccount.google.com
Click "connected apps & sites",
Turn "Allow less secure apps" to "ON" (bottom of the page).
Just I checked up with your code no error in that. you've to enable https://www.google.com/settings/security/lesssecureapps
<?php
include "PHPMailer_5.2.4/class.phpmailer.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'test#gmail.com';
$mail->Password = 'test#12123#';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->addAddress('abc#gmail.com');
$mail->setFrom('abc#gmail.com');
$mail->Subject = 'Test';
$mail->Body = 'Testing';
if($mail->send()) {
echo 'Message has been sent';
} else {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>

Php mailer body is empty

Iam using PHP mailer to send an Email the message sent but email body is Empty
here is my code
foreach($results as $result)
{
$email = $result['email'];
$body = 'Hello'.$result['username'].' we remind you to return the book to library after' .$result['days'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.myhost.com;';
$mail->SMTPAuth = true;
$mail->Username = 'send#myhost.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From = 'send#myhost.com';
$mail->FromName ='Bookstore';
$mail->addAddress($email, 'username');
$mail->Subject = 'Book returned Time';
$mail->Body = $body;
$mail->IsHTML(true);
if(!$mail->send()) {
echo 'Message could not be sent.';
//echo 'Mailer Error: ' . $mail->ErrorInfo; return $user ;
} else {
echo 'done';
}
}

PHP email not sent

I use this code to send an email:
When I open the mail.php file in my browser. Nothing will send. The browser will load a blank page with no message displayed saying the email was sent. I have been searching on StackOverflow and other websites for a solution. Can someone help me?
<?php
require_once("phpmailer\class.phpmailer.php");
// path to the PHPMailer class.
require_once("phpmailer\PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = "25";
// 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl';
// Uncomment this line if you want to use SSL.
$mail->Username = "emailer#my.domain";
$mail->Password = "password";
$mail->From = "example#gmail.com";
$mail->FromName = "Susan Sender";
$mail->AddAddress("rachel#my.domain", "Rachel Recipient");
//$mail->AddReplyTo("Your Reply-to Address", "Sender's Name");
$mail->Subject = "Hi!";
$mail->Body = "Hi! How are you?";
$mail->WordWrap = 50;
if(!$mail->Send())
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
}
else {
echo 'Message has been sent.';
}
?>

phpmailer Error after sending Email

Code: -
$mail = new PHPMailer();
$body="<b>This mail is sent using PHP Mailer</b>";#HTML tags can be included
$mail->IsSMTP();
$mail->SMTPAuth = true; #enable SMTP authentication
$mail->SMTPSecure = "tls"; #sets the prefix to the server
$mail->Host = "smtp.gmail.com"; #sets GMAIL as the SMTP server
$mail->Port = 587; #set the SMTP port
$mail->Username = "morelifelondon#gmail.com"; #your gmail username
$mail->Password = "***********"; #Your gmail password
$mail->From = $email;
$mail->FromName = $name ;
$mail->Subject = "Enquiry";
$mail->Body = $messages;
$mail->AddAddress("morelifelondon#gmail.com","contact");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Mail has Been Sent.';
}
}
I want that morelifelondon#gmail.com is replaced by abhishek#gmail.com. Is this possible ?
$mail->AddAddress("abhishek#gmail.com","contact");
or use
$mail->AddCC("abhishek#gmail.com","contact");

Categories