I want to send the emails via original old school sendmail.
In what way i need to change this CODE to work with sendmail?
i have tried but i always get very ugly errors, i tried to change IsMail to IsSedmail but still does not send the original way.
Phpmailer sends 3 email and the website is taking a lot time to send, so i want to go to the old plain "mail(to...." but the problem is that i`m lost in all the code so please Help.
function send_mail($rec_email,$subject,$message, $IsHtml=false, $cc=array(), $bcc=array()) {
global $THIS_BASEPATH, $btit_settings;
if (!method_exists('PHPMailer','IsMail'))
include($THIS_BASEPATH.'/phpmailer/class.phpmailer.php');
$mail=new PHPMailer();
if ($btit_settings['mail_type']=='php') {
$mail->IsMail(); # send via mail
if (!empty($cc))
$mail->AddCustomHeader('Cc: '.implode(',',$cc));
if (!empty($bcc))
$mail->AddCustomHeader('Bcc: '.implode(',',$bcc));
} else {
$mail->IsSMTP(); # send via SMTP
$mail->Host = $btit_settings['smtp_server']; # SMTP servers
$mail->Port = $btit_settings['smtp_port']; # SMTP port
$mail->SMTPAuth = true; # turn on SMTP authentication
$mail->Username = $btit_settings['smtp_username']; # SMTP username
$mail->Password = $btit_settings['smtp_password']; # SMTP password
if (!empty($cc))
foreach($cc as $carbon_copy)
$mail->AddCC($carbon_copy[0],$carbon_copy[0]);
if (!empty($bcc))
foreach($bcc as $blind_carbon_copy)
$mail->AddBCC($blind_carbon_copy[0],$blind_carbon_copy[0]);
}
$mail->From = $btit_settings['email'];
$mail->FromName = $btit_settings['name'];
$mail->CharSet = $btit_settings['default_charset'];
$mail->IsHTML($IsHtml);
$mail->AddAddress($rec_email);
$mail->AddReplyTo($btit_settings['email'],$btit_settings['name']);
$mail->Subject = $subject;
$mail->Body = $message;
return ($mail->Send())?true:$mail->ErrorInfo;
}
Thank You very much.
PHPmailer is not the culrpit for "slowness", it's probably the SMTP server you've specified. Do not stop using PHPmailer, though. PHPmailer does tons of extra stuff behind the scenes to send mail correctly.
To send mail out through the local server using PHP's mail() replace:
$mail->IsSMTP(); # send via SMTP
$mail->Host = $btit_settings['smtp_server']; # SMTP servers
$mail->Port = $btit_settings['smtp_port']; # SMTP port
$mail->SMTPAuth = true; # turn on SMTP authentication
$mail->Username = $btit_settings['smtp_username']; # SMTP username
$mail->Password = $btit_settings['smtp_password']; # SMTP password
With:
$mail->isMail();
That's it.
If you are certain that the server has either Sendmail [or a drop-in replacement like Postfix or Exim] installed then you can use:
$mail->isSendmail();
However, by using the web server to send out mail you are now dependent on:
The installed MTA being configured correctly, which they frequently aren't.
The reputation of the web server according to various blacklists. Generally, web servers have s**t reputations because anyone can drop outbound mail into the queue without authentication.
Related
I had successfully setup a web app using WAMPSERVER on a desktop used by a few people internally, this used PHPMailer to an internal SMTP server without encryption or authentication and it worked.
That desktop crashed and I've migrated to a "new" desktop. I had an SVN setup so I was even using most of the same files and config. One difference which might matter is that the old desktop was 64-bit and the new is 32-bit. This means I'm using different versions of WAMPSERVER.
The mailer just hangs. I don't get a PHP error or a PHP timeout. I just never reach the end of my script. The crazy part about this is that it works with authentication, ssl, and gmail. It just won't work with the extra simple case I need.
This works:
<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.gmail.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myemail#gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
$mail->AddAddress('toemail#supersecret.com', 'John Doe');
$mail->SetFrom('something#gmail.com', 'First Last');
$mail->Send();
?>
this used to, but now does not:
<?php
require('class.phpmailer.php');
$mail=new PHPMailer();
$mail->ISSMTP();
$mail->Host='smtp.internal.com';
$mail->Subject='test subj';
$mail->Body='the body email test';
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->AddAddress('myaddress#somewhere.com', 'John Doe');
$mail->SetFrom('someaddress#mightbereal.com', 'First Last');
$mail->Send();
?>
The only thing I get from debug is
CLIENT -> SMTP: EHLO thedesktophostname
No errors display on the page and nothing in the apache log, where I normally get PHP errors, if they don't display.
I can telnet to the host from the desktop on port 25 and even type in the EHLO command and get a good response from the server.
I don't remember having this issue before, although it's possibly I've already solved it once. I couldn't find anything that helped here or on The Google.
Please help. Thanks.
Hijacking the post to say i had the same issue but had set the port to 465 without setting SMTPSecure to 'ssl' in the example its set TLS by default
If you have a server hosted in Hostgator (shared hosting), this is what solved for me:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
(even though the official example in PHPMailer suggests using ENCRYPTION_STARTTLS)
sadly this probably won't ever help anyone else who has this same problem, but I was able to get everything working by just changing the port to 465.
Eventually found solution for my configuration.
Just add ssl:// to smtp.google.com
$mail->Host = 'ssl://smtp.gmail.com';
I had the same issue. Nothing displays after the send method.
I realized that the encryption was wrong, I did use SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
// Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted
with PHP, we can easily send email with current server if we have installed mail server or DirectAdmin or CPanel and so on ...
now think the situation that we need specif server sends emails, one server should be mail server and another should be Apache + PHP ? how can I achieve that ?
I am using ubunto for both server
Try SMTP to send the mail from Another server->
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "username"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
There can be at least these two approaches.
1. Using mailer server as SMTP
Install and configure an SMTP software like Postfix on the
system you want to make mail server
Then in the webserver use a library like PHPMailer of
SwiftMailer to send email using the mailserver's ip address and
created smtp user.
2. Using mail sererver's PHP mail()
This is the other way around.
Access the database installed in the webserver in the mailserver
machine by using the webserver's ip address as the hostname and the
respective username and password.
You will need to enable remote connection to the database. If its
mysql then you can see the following question:
Remote Connections Mysql Ubuntu
I've been using PHPmailer (https://github.com/Synchro/PHPMailer) to send email through amazon SES for a few months. At some time in the last two weeks it has stopped working, and I haven't touched it. I'm getting an error msg:
SMTP Error: Could not connect to SMTP host.
This is my code.
public function sendEmail($to,$subject,$body){
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'amazonaws....'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mySMTPuname'; // SMTP username
$mail->Password = 'smtpPword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'example';
$mail->FromName = 'me';
$mail->AddAddress($to); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
return $mail->Send();
}
My amazon account is still upto date and active. Is there any way to print out more detailed error msgs for debugging? Has there been any known issues lately?
Try :
$mail->SMTPDebug = 1;
// if you're using SSL
$mail->SMTPSecure = 'ssl';
// OR use TLS
$mail->SMTPSecure = 'tls';
This is a very old question but I just had the same problem so it may still be relevant to others.
If it stopped working without you changing anything it is probably connected to your hosting company / isp blocking SMTP traffic from your server to other servers.
There are a few topics on this, as multiple hosting companies using Cpanel and also Godaddy have implemented such measures for combating spam.
Try:
$mail->SMTPDebug = 3;
to get the maximum level of detail on the error.
One solution is to use the mail server in the same hosting account (if it blocks SMTP to the outside it probably has an internal service you can use).
To keep using Amazon SES you need to open SMTP traffic on your server.
IF you have control over Cpanel/WHM "tweak settings" you can do it yourself, otherwise you need to ask your hosting provider.
Check this answer for details "Password not accepted from server: 535 Incorrect authentication data" when sending with GMail and phpMailer
I want to be able to send mails in Hostgator via office365. I was able to do it with Gmail, but can not set it up to work with office365.
It works on my 2 other servers. The only problem is Hostgator.
Do I have to fix something or Hostgator have to take some action?
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "pod51014.outlook.com";
$mail->Port = 587;
$mail->Username = "usernamehere";
$mail->Password = "************";
/* ... addaddres, reply, subject, message -> the usual stuff you need ... */
$mail->Send();
?>
I just keep getting following response:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
I was on the support chat with them and the 587 port should be open.
I think hostgator is blocking outgoing emails but accepts incoming emails.
If your hosting provider doesn't allow outbound SMTP mail, I suggest you take a look at Microsoft Graph - a REST API which let's you also send e-mails and do much more. You can use for example oauth2-azure library to interact with it very easily from your PHP code.
Try these things. Maybe something will work.
Set the host to:
$mail->Host = 'smtp.office365.com';
Do not set a port at all:
//$mail->Port = 587;
After updating to WHM/cPanel 11.30.0, PHPMailer mails are now being rejected by exim. This is my code:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Password = '****';
$mail->Host = "mail.***.com";
$mail->Username = '***#***.com';
$mail->From = "***#***.com";
$mail->FromName = '***#***.com';
$mail->AddAddress($recipient);
$mail->Subject = $subject;
$mail->Body = $body;
$result = $mail->Send();
PHPMailer is returning with no errors but in the exim reject log it says
H=(localhost.localdomain) [a.n.i.p] F=<...#....com> rejected RCPT <...#....com>: (localhost.localdomain) [a.n.i.p] is currently not permitted to relay through this server. Perhaps you have not logged into the pop/imap server in the last 30 minutes or do not have SMTP Authentication turned on in your email client.
Can anyone help?
This is a really common, convoluted error message from exim, but the short of it is that the server isn't set up to accept email from the recipient domain.
It possible that the update has cleared out any IP's defined in your relayhosts. Make sure the host your sending from is added to the /etc/exim_smtp_whitelist, and that this is being used in your cpanel configuration.
WHM > Exim Configuration Editor > Advanced Editor
accept hosts = /etc/exim_smtp_whitelist