My PHPmailer from Github does work on my local host but not on my Firebase hosted website. When I submit on my website it downloads the file. Now how to solve it? Do I have to put some extra code in? Someone experienced with Firebase?
<?php
// get variables from the form
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Load Composer's autoloader
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try{
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example#gmail.com'; // SMTP username
$mail->Password = '°°°°°°°'; // SMTP password
$mail->SMTPSecure = 'TLS'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
// Sender
$mail->setFrom($email, $name);
// Recipients
$mail->addAddress('example#gmail.com', 'Luk Ramon'); // Add a recipient
// Body content
$body = "<p>You received an email from your website <br>name:<strong>".$name." </strong><br>subject: <strong>".$subject."</strong><br>message:<br><i>".$message."</i></p> Contact back on ".$email;
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Company-name message from '.$name;
$mail->Body = $body;
$mail->AltBody = strip_tags($body);
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
Firebase hosting does not support PHP which is why the file is being downloaded.
You'd need to write this in Javascript to use with Firebase - https://firebase.google.com/docs/hosting/functions
I have a problem, with my code beneath I get this error message:
Message could not be sent.Mailer Error: SMTP Error: The following recipients failed: !Censored!
I have looked into the Host, Port, Username, Password, Recipient and all is correct, what is the problem? Thank you!
Could you please explain too cuz Im new to PHP-coding
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['amne'];
$message = $_POST['message'];
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = '!Censored!'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '!Censored!'; // SMTP username
$mail->Password = '!Censored!'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = $email;
$mail->FromName = $name;
$mail->addAddress('!Censored!'); // Add a recipient
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
EDIT: I found the problem, the problem was not in the php code itself. It was in the contact form. The problem started when I put the variables as names and emails. If the email is not verified, it does not work.
This error can be caused by a few different things. You can get a better idea of the reason by adding the following line to your PHPMailer script:
$mail->SMTPDebug = 2; //<-- For debugging
Once you do that, you can check the following things that may be causing the error:
1.) A corrupt class.phpmailer.php file.
2.) The error may be caused by protection put in place by your ISP. Check with them.
3.) It could be a problem with the recipient's/sender's email addresses.
4.) Set SMTPAuth to true for PHPMailer class.
5.) Comment out the following line in your PHPMailer script: $mail->isSMTP();
Mostly, There is possibility that Your phpmailer class file is corrupted.
Download the latest version: https://github.com/PHPMailer/PHPMailer
I am having this problem for my php mailer function. I tried changing the required file but still its the same. Can anyone help me with this error.
This is my phpmailer code:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = "testnoreply#gmail.com";
$mail->Password = "test";
$mail->SetFrom("testnoreply#gmail.com");
$mail->Subject = "Membership expire notice";
$mail->Body = "Dear ICONIS member your membership is going to expire please renew it";
$mail->AddAddress($em);
if (!$mail->Send()) {
echo "Mailer Error: " .$mail->ErrorInfo;
} else {
echo "Mail has been sent";
}
Are you sure you have both the class.phpmailer.php AND the class.smtp.php in your folder?
Try including class.smtp.php before including class.phpmailer.php, as the following:
<?php
include 'class.smtp.php';
include 'class.phpmailer.php';
// your code goes here
Then tell if you got some error.
just download all files, extract the files into a folder and include PHPMailerAutoload.php from the folder.
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
/*======================================*/
/*======================================*/
require 'YOURFOLDERNAME/PHPMailerAutoload.php';
/*======================================*/
/*======================================*/
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto#example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
try
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
instead of
require 'class.phpmailer.class.php';
$mail = new PHPMailer;
I am new to PHP. I was trying to send myself a sample e-mail through PHPmailer. I am using gmail's smtp server. I am trying to send a sample mail from my gmail account to my yahoo account. But I am getting the error : Mailer Error: SMTP connect() failed.
Here is the code :
<?php
require "class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "ssl://smtp.gmail.com";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myemail#gmail.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
$webmaster_email = "myemail#gmail.com"; //Reply to this email ID
$email="myyahoomail#yahoo.in"; // Recipients email ID
$name="My Name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->Port = 465;
$mail->FromName = "My Name";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"My Name");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "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";
}
?>
I am using WAMP server on a Windows 7 64-bit machine. What could be the prob?
Please help me solve this. Thanks!
The solution of this problem is really very simple. actually Google start using a new authorization mechanism for its User.. you might have seen another line in debug console prompting you to log into your account using any browser.! this is because of new XOAUTH2 authentication mechanism which google start using since 2014.
remember.. do not use the ssl over port 465, instead go for tls over 587. this is just because of XOAUTH2 authentication mechanism. if you use ssl over 465, your request will be bounced back.
what you really need to do is .. log into your google account and open up following address
https://www.google.com/settings/security/lesssecureapps
and check turn on . you have to do this for letting you to connect with the google SMTP because according to new authentication mechanism google bounce back all the requests from all those applications which does not follow any standard encryption technique.. after checking turn on.. you are good to go..
here is the code which worked fine for me..
require_once 'C:\xampp\htdocs\email\vendor\autoload.php';
define ('GUSER','youremail#gmail.com');
define ('GPWD','your password');
// make a separate file and include this file in that. call this function in that file.
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->SMTPAutoTLS = false;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
You need to add the Host parameter
$mail->Host = "ssl://smtp.gmail.com";
Also, check if you have open_ssl enabled.
<?php
echo !extension_loaded('openssl')?"Not Available":"Available";
Solved an almost identical problem, by adding these lines to the standard PHPMailer configuration. Works like a charm.
$mail->SMTPKeepAlive = true;
$mail->Mailer = “smtp”; // don't change the quotes!
Came across this code (from Simon Chen) while researching a solution here, https://webolio.wordpress.com/2008/03/02/phpmailer-and-smtp-on-1and1-shared-hosting/#comment-89
Troubleshooting
You have add this code:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
And Enabling Allow less secure apps:
"will usually solve the problem for PHPMailer, and it does not really make your app significantly less secure. Reportedly, changing this setting may take an hour or more to take effect, so don't expect an immediate fix"
This work for me!
$mail->SMTPKeepAlive = true;
$mail->isSendMail(); // instead of isSMTP();
On shared hosting, your mail server may occasionally experience connection issues.
Here I found solution
[Edit]
Here is the link content, in case the link stop working for some reason (it happens)
PHPMailer and SMTP on 1and1 shared hosting
I use PHPMailer on my 1and1 shared hosting account. Recently, I could not send email anymore.
I tried debugging and this is the error that PHPMailer throws:
Language string failed to load: connect_host
After googling for a solution and trying different SMTP servers, accounts and SMTP ports, I decided to switch to sendmail and it worked like a charm! All I needed to do was to replace $mail->isSmtp() with:
$mail->isSendMail()
sendMail is located in its default location on 1and1 servers : /usr/sbin/sendmail, so no change of settings was required.
Conclusion:
1and1 probably closed its outgoing SMTP ports on its shared hosting servers. Consequently, if you use PHPMailer, don’t use SMTP mode anymore.
If anyone is still unable to solve the issue, please check following thread and follow callmebob's answer.
PHPMailer - SMTP ERROR: Password command failed when send mail from my server
I fixed it ...
https://github.com/PHPMailer/PHPMailer/tree/5.2-stable
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'm7#gmail.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('m7#gmail.com', 'Mailer');
$mail->addAddress('dot#gmail.com', 'User'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Turn on access and enjoy..! That is on Gmail account setting.
You are missing the directive that states the connection uses SSL
require ("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn of SMTP authentication
$mail->Username = "YAHOO ACCOUNT"; // SMTP username
$mail->Password = "YAHOO ACCOUNT PASSWORD"; // SMTP password
$mail->SMTPSecure = "ssl";
$mail->Host = "YAHOO HOST"; // SMTP host
$mail->Port = 465;
Then add in the other parts
$webmaster_email = "myemail#gmail.com"; //Reply to this email ID
$email="myyahoomail#yahoo.in"; // Recipients email ID
$name="My Name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "My Name";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"My Name");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "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";
}
As a side note, I have had trouble using Body + AltBody together although they are supposed to work. As a result, I wrote the following wrapper function which works perfectly.
<?php
require ("class.phpmailer.php");
// Setup Configuration for Mail Server Settings
$email['host'] = 'smtp.email.com';
$email['port'] = 366;
$email['user'] = 'from#email.com';
$email['pass'] = 'from password';
$email['from'] = 'From Name';
$email['reply'] = 'replyto#email.com';
$email['replyname'] = 'Reply To Name';
$addresses_to_mail_to = 'email1#email.com;email2#email.com';
$email_subject = 'My Subject';
$email_body = '<html>Code Here</html>';
$who_is_receiving_name = 'John Smith';
$result = sendmail(
$email_body,
$email_subject,
$addresses_to_mail_to,
$who_is_receiving_name
);
var_export($result);
function sendmail($body, $subject, $to, $name, $attach = "") {
global $email;
$return = false;
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = $email['host']; // SMTP server
// $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = $email['host']; // sets the SMTP server
$mail->Port = $email['port']; // set the SMTP port for the GMAIL server
$mail->SMTPSecure = "tls";
$mail->Username = $email['user']; // SMTP account username
$mail->Password = $email['pass']; // SMTP account password
$mail->AddReplyTo($email['reply'], $email['replyname']);
if(stristr($to,';')) {
$totmp = explode(';',$to);
foreach($totmp as $destto) {
if(trim($destto) != "") {
$mail->AddAddress(trim($destto), $name);
}
}
} else {
$mail->AddAddress($to, $name);
}
$mail->SetFrom($email['user'], $email['from']);
$mail->Subject = $subject;
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
if(is_array($attach)) {
foreach($attach as $attach_f) {
if($attach_f != "") {
$mail->AddAttachment($attach_f); // attachment
}
}
} else {
if($attach != "") {
$mail->AddAttachment($attach); // attachment
}
}
$mail->Send();
} catch (phpmailerException $e) {
$return = $e->errorMessage();
} catch (Exception $e) {
$return = $e->errorMessage();
}
return $return;
}
if everything fails then for gmail you must turn on access to 3rd party apps to connect to ur gmail account.
https://www.google.com/settings/security/lesssecureapps // turn it
on
Just make sure you passed the right parameters
eg. the correct outgoing server host, username, and password
$mail->SMTPDebug = false;
$mail->Host = 'email_smtp_host'
$mail->SMTPAuth = false
$mail->Username = 'username'
$mail->Password = 'password'
$mail->SMTPSecure 'tls'
$mail->Port = '587'
If you're using VPS and with httpd service, please check if your httpd_can_sendmail is on.
getsebool -a | grep mail
to set on
setsebool -P httpd_can_sendmail on
Try adding this line to your script. This worked for me!
$mail->Mailer = “smtp”;
This is usually a result of the server not accepting SSLv2 or SSLv3 connections which is a standard for cPanel/WHM in favor of TLS only connections. You can check this by going to WHM>>Service Configuration>>Exim Configuration Manager -> Options for OpenSSL
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
<?php
use PHPMailer\PHPMailer\PHPMailer;
require_once "PHPMailer/src/Exception.php";
require_once "PHPMailer/src/PHPMailer.php";
require_once "PHPMailer/src/SMTP.php";
$mail = new PHPMailer();
$mail ->isSMTP();
$mail ->Host ="smtp.gmail.com";
$mail -> SMTPAuth = true;
$mail ->Username = 'youremail#gmail.com';
$mail ->Password = 'password';
//$mail ->SMTPSecure=PHPMailer::ENCRYPTION_STARTTLS;
$mail ->Port = '587';
$mail ->SMTPSecure ='tls';
$mail ->isHTML(true);
$mail ->setFrom('youremail#gmail.com','email send name');
$mail ->addAddress('receiver#gmail.com');
$mail ->Subject = 'HelloWorld';
$mail ->Body = 'a test email';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
if ($mail->send()){
echo "Message has been sent successfully";
}else{
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
make sure that you configure less secure app settings in gmail using this link https://www.google.com/settings/security/lesssecureapps and make sure you downloaded PHPMailer-master.zip from github
working fine with MAMP server locally :)
After days of searching, I found out that the protocol name needs to be in lowercase.
$mail->SMTPSecure = "ssl"; # lowercase
find the "class.smtp.php" file
original:
$this->smtp_conn =fsockopen(
$host,
$port,
$errno,
$errstr,
$timeout
);
change to:
$this->smtp_conn = #stream_socket_client(
$host,
$port,
$errno,
$errstr,
$timeout
);
I'm using PHPmailer. It works when $mail->SMTPDebug = true; but when I remove that line, it silently fails. I say silently fails as it doesn't give any errors, and yet the email doesn't seem to be delivered.
$mail = new PHPMailer;
$mail->SMTPDebug = true;
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->Username = 'xxxxx#gmail.com';
$mail->Password = 'xxxxx';
$mail->Mailer = 'smtp';
$mail->AddReplyTo('support#xxxxx.com', 'xxxxx Support');
$mail->From = 'xxxxx#gmail.com';
$mail->FromName = 'xxxxx Applications';
$mail->Sender = 'xxxxx Applications';
$mail->Priority = 3;
//To us
$mail->AddAddress('xxxxx#xxxxx.com', 'xxxxx xxxxx');
//To Applicant
$mail->AddAddress($email, $first_name.''.$last_name);
$mail->IsHTML(true);
$last_4_digits = substr($card_num, -4);
//build email contents
$mail->Subject = 'Application From '.$first_name.' '.$last_name;
$mail->Body = $body_html;
$mail->AltBody = $body_text;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
By setting
$mail->SMTPDebug = false;
instead of omitting the line completely, it works every time.
I think you are using an outdated version of the phpmailer, please use composer to install. Check of the version of the PHP mailer is 6.4+
Below is an example of how to install the latest version using the composer.
composer require phpmailer/phpmailer
When you look at the official repository code - line 402
https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php
you see that $SMTPDebug is set to 0, so it can't be the reason why it fails silently.
public $SMTPDebug = 0;
Below provides an example guide to send the email using phpmailer.
This example worked for me without the use of the SMTPDEBUG not specifying. Also, PHPMailer(true) makes the exceptions enabled which can be useful so that it doesn't fail silently.
//Load Composer's autoloader
require 'vendor/autoload.php';
//Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'user#example.com'; //SMTP username
$mail->Password = 'secret'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); //Add a recipient
$mail->addAddress('ellen#example.com'); //Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
To provide more details to the question:
What is the reason why email is not sent when SMTPDebug information is omitted?
As the version of PHPMailer used was not specified, I tried using the latest version at the time of the question which was v5.2.7 released on the 12th of September, 2013, but I also tried the oldest non-dev version, 5.2.2 (that was available on packagist) and all in between (v5.2.4, v5.2.5 and v5.2.6).
I could not replicate the issue and so it's likely that it was not caused by omitting the SMTPDebug parameter in PHPMailer unless other dependencies, operating system or PHP version played a role in the problem but without details, it's not possible to ascertain.
In these old versions the SMTPDebug parameter was used like so
/**
* SMTP class debug output mode.
* Options: 0 = off, 1 = commands, 2 = commands and data
* #type int
* #see SMTP::$do_debug
*/
public $SMTPDebug = 0;
...
protected function edebug($str)
{
if (!$this->SMTPDebug) {
return;
}
...
Where edebug was used for simple debug logging:
$this->edebug($e->getMessage() . "\n");
So it would be quite difficult for a bug to occur that would cause the described effect as a result of omitting SMTPDebug.
If the bounty placer is still having trouble, try #mahen3d's suggestions or ask a new question providing a reprex.