PHP mailer not sending mails to particular groups - php

Am using PHP mailer for sending emails.For individual users and for some groups i am able to send mails but for some other groups the mails are not going.Am using Microsoft exchange server for the mails.And there are no errors shown in the log file in the host.
PHP mailer code:
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'email.domain.com';
$mail->SMTPAuth = true;
$mail->Username = 'username#domain.com';
$mail->Password = '********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('username#domain.com');
$addresses = 'Recipients#domain.com';
$mail->isHTML(true);
Thanks in advance.

Related

How to resolve SMTP could not connect error? [post STARTTLS problem]

I have installed php mailer using composer composer require phpmailer/phpmailer. I followed instructions from this website https://www.geeksforgeeks.org/how-to-send-an-email-using-phpmailer.
Below is my code for sending email.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try
{
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'mail.example.in';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('owner#gmail.com', 'Owner');
$mail->addAddress('receipent#gmail.com');
$mail->isHTML(true);
$mail->Subject = "Hello this is subject";
$mail->Body = "Hello this is message;
$mail->send();
echo "Mail has been sent successfully!";
}
catch (Exception $e)
{
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
When I comment $mail->isSMTP(); and send mail, I get the result as message sent but I dont get it in my Gmail inbox.
when I uncomment $mail->isSMTP(); I get error message as shown in below image.
My project is hosted in godaddy server.
Even if I use php mail() function to send mail, response is mail send successfully, but it does not get delivered into my Gmail inbox
If you want to use Gmail, you should follow the steps here to manually add Google MX records to your GoDaddy account:
https://uk.godaddy.com/help/point-my-domains-email-service-to-google-7936
Unfortunately it takes some days for changes to be reflected.
Then you need to disable security features, change your php mailer config like:
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Port = 25;
Hope this solves.
------EDIT------
Later I figured out that the emails go to spam folder when the port is 25. I changed the connection to TLS and now I receive them as normal.
Here is the code from my website, it works on Godaddy, I receive e-mails to my gmail account.
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'true';
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "********#gmail.com";
$mail->Password = "**********";
$mail->SetFrom("********#gmail.com");
$mail->AddAddress("********#gmail.com");
$mail->Subject = " your subject";
$mail->Body = "your body";

PHP Mailer SMTP Error: Data not accepted

i have a strange problem. I try to send a mail with a pdf document as attachment with php mailer. The script works fine, as long i call it in the browser. When i try to call it from console inside a batch, i'm getting SMTP Error: Data not accepted.
My system is a windows 2008 R2 Server with xampp. The only difference is the user context. When i call the script in the browser, i guess apache will call my script and the apache service is running as lokal system. When i'm starting the batch file the script will probably be called by the user i'm logged in with right ?
Maybe someone could help me out with that problem :)
Greets Mike
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";
$mail->SetFrom('mymail#outlook.com', 'Me');
$mail->AddReplyTo("mymail#mydomain.com", "Me");
This is my batch:
C:\xampp\php\php-cgi.exe C:\xampp\htdocs\bericht\sendMail2.php
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "username";
$mail->Password = "password";
$mail->SetFrom('mymail#outlook.com', 'Me');
$mail->AddReplyTo("mymail#mydomain.com", "Me");
This is my batch:
C:\xampp\php\php-cgi.exe C:\xampp\htdocs\bericht\sendMail2.php

PHP Sign-Up/ Email Verification

Thanks in advance.
Below is code from PHPmailer (https://github.com/Synchro/PHPMailer) which is giving me a few problems. It works along side this PHP sign-up (http://www.codingcage.com/2015/09/login-registration-email-verification-forgot-password-php.html). I know it works other then the email because the table in the database does recieve the values. I can manually update the table and and allow myself to log-in. It does send out a Error 500 page.
function send_mail($email,$message,$subject)
{
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->AddAddress($email);
$mail->Username = "EMAIL#gmail.com";
$mail->Password = "PASSWORD";
$mail->SetFrom('robert.m.smith112#gmail.com','Coding Cage');
$mail->AddReplyTo("robert.m.smith112#gmail.com","Coding Cage");
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
}

Email to SMS using PHPMailer

Good Day, I found in google that you can send sms messages just by typing the recipients mobile number plus the sms gateway using phpmailer and I tested it on my mobile phone but for some reason I don't received any sms messages. This is my php code:
require($_SERVER['DOCUMENT_ROOT']."/PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
// Configure smptp
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "**********#gmail.com";
$mail->Password = "******";
// Compose
$mail->Subject = "Testing";
$mail->Body = "Testing";
// Send to
$mail->AddAddress("***********#mysmart.mymobile.ph");
var_dump($mail->send()); //Send!
and here is the var_dump
I am residing in the philippines. Thanks.

phpmailer & in subject coming in as &

I am sending emails using PHPMailer and through my gmail account with SMTP. It all works except when there is an & in the subject, then in my inbox the subject has &
Any way to make this not happen? I've tried setting the charset and encoding the subject.
My code is below
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = false;
$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 = "myusername#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('from#somesite.com', 'From Person');
$mail->AddReplyTo("from#somesite.com", "From Person");
$mail->Subject = 'An example with a & in the middle';
$mail->MsgHTML('Some text to send');
$mail->AddAddress('myusername#gmail.com');
$mail->Send()
Thank You
Try using this code, let me know if it helps.
$mail->Subject = "=?UTF-8?B?".base64_encode($_POST['subject'])."?=";

Categories