I'm setting up an email configuration with PHPMailer and just work fine with local email in my office, but since I want use Sendinblue as an email API I just stucked and it didn't work.
I tried to find some suggest to fixed it but stucked. Did anyone try to figure out what I'm looking for about Sendinblue with PHPMailer?
With PHPMailer Library in background, I usually use this code to run my program
function send_mail2($from,$from_name,$to,$to_name,$cc,$cc_name,$cc2,$cc_name2,$cc3,$cc_name3,$subjek,$template,$is_smtp,$usermail,$password){
$sendmail = new PHPMailer();
if($is_smtp = 'Y'){
$sendmail->IsSMTP(); // enable SMTP
// $sendmail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$sendmail->SMTPAuth = true; // authentication enabled
$sendmail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$sendmail->Host = "192.x.x.x";
$sendmail->Port = 465; // or 587
$sendmail->Username = "xxx#xxx.com";
$sendmail->Password = "xxx";
}
$sendmail->setFrom("xxx#xxx.com","xxx#xxx.com"); //email pengirim
$sendmail->addReplyTo("xxx#xxx.com","xxx#xxx.com"); //email replay
$sendmail->addAddress($to,$to_name);
$sendmail->AddCC($cc,$cc_name);
$sendmail->AddCC($cc2,$cc_name2);
$sendmail->AddCC($cc3,$cc_name3);
$sendmail->Subject = $subjek;
$sendmail->Body=$template;
$sendmail->isHTML(true);
if(!$sendmail->Send()) {
return "failed";
}else{
return "success";
}
}
I just want to find how to use Sendinblue with PHPMailer.
First of all, it looks like you're using an old version of PHPMailer and have based your code on a very old example, so upgrade.
It doesn't look like you're even trying to use sendinblue; you're pointing your script at a local mail server. Because you're using a literal IP address, SSL will never work because it will fail to verify the certificate.
If you want to use sendinblue directly from PHPMailer, you need to use sendinblue's SMTP servers, and that will be covered in their documentation. If they don't provide an SMTP service (like say mailgun does), you will need to use their HTTP API instead (which has plenty of documentation). You can't use PHPMailer for talking to that, though you can use it for generating messages to send, for example by doing everything as you currently are except don't call send(); do this instead:
$message = $sendmail->getSentMIMEMEssage();
This will give you a fully-formatted RFC822 message ready to submit to an HTTP API.
When you need to configure sendinblue with PHPMailer,
At that time, first, get all configuration detail from your sendinblue account
like Host, Username, Password
And then your PHPMailer use getSentMIMEMEssage(); instend of $mail->isSMTP() or $mail->isMail()
Please check the below screenshot for reference.
Related
everybody,
I am working on Email system to send emails via SMTP protocol with PHP,
everything goes fine and now I can send messages without a problem, I have tow problems Actually and I hope I will find a solution,
1 - I send email to users using a phpmailer library, but I can not control and get the result of sending email because I send about 10 emails at one SMTP connection.
this is my send code
$mail = new PHPMailer;
$froms=$respu['froms'];
$mail->Timeout = 3600;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $respu['server']; // Specify main and backup SMTP servers
$mail->SMTPAuth = $respu['authentication']; // Enable SMTP authentication
$mail->Username = $respu['username']; // SMTP username
$mail->Password = $respu['password']; // SMTP password
$mail->SMTPSecure = $respu['security']; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $respu['port']; // TCP port to connect to
$mail->SetFrom($respu['username'],$froms);
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->MsgHTML($message);
if(!$mail->Send()) {
//$errors=$mail->getSMTPInstance()->getError();
$date=date('Y-m-d h:i');
echo $msg= "Message Not Sent: to $to " . $mail->ErrorInfo;
$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ('$msg','$to','$date',0) ";
$this->query_return($sql);
exit();
} else {$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ( 'Message Sent Successfully ','$to','$date',1) ";
$this->query_return($sql);
}
the if(!$mail->Send()) condition return true every time even if the email is wrong . it working like to test if the SMTP connection is done or not, I want to know if the email received by users or not.
my second problem is, I have more than 3000 mail address and I want to send email to them at the same time, what is happening is the procedure take a long time and I have to wait for a long time to finish it, how can I do it faster.
For sending to lists, use the mailing list example provided with PHPMailer as a starting point. Also read the wiki article about sending to lists.
For maximum performance, you want to be submitting to a local or nearby mail server, which then takes responsibility for onward delivery. Some messages may fail to be delivered, in which case you will need to rely on bounce handlers; when a message fails to send, it will be returned to the Return-path address, which you can control by setting the Sender property in PHPMailer (by default it uses your From address). Note that as a sender you should never set a return-path header yourself; that's the receiving server's job.
Be warned though: handling bounces is very unpleasant; because bounce messages are fairly "invisible" in normal use, it means that they are extremely variable in quality. For example, it's possible for bounces from some Microsoft Exchange servers to omit the address that the message bounced for! You can handle that scenario (and many other shortcomings of badly-configured mail servers) by using VERP addressing to help you identify original recipient addresses, or even individual messages. However you deal with this, you need to be on very good speaking terms with your mail server. Using an external service to handle sends like this isn't necessarily any better, since they face exactly the same problems, though at least they may deal with much of the unpleasantness of bounce handling.
FYI I run https://smartmessages.net, an email marketing service; it's built around PHPMailer (which is partly why I'm the maintainer), and we can send at about 300 messages/second (using a very good mail server), so decent throughput is entirely possible with PHPMailer.
I'm attempting to send an email address out to registrants who register for my site however this section of my code is not running. I'm attempting to find out why. I've followed all the necessary documentation. I replaced this section with php's mail function for debugging to see if it'll send an email on my server and it will. Does anybody have any thoughts on what it could be?
// User was successfully created and the user needs to verify their account.
// Send registered an email informing them how to validate their account.
$this->load->library('email');
$this->email->from('owner#owner.com', 'Owner Name');
$this->email->to($post_email_address);
$this->email->subject('Site Name Here Registration');
$this->email->message('Thank you for registering for our site. Here is your registration key to activate your account: '.$registration_key.' Please click on the following link to activate your account.<br />'.anchor('project-manager/login/verify/'.$registration_key, 'Click Here To Activate Your Account', ''));
$this->email->send();
Here is the configurations for the email.com inside of the application/config directory.
<?php
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
I know that it seems unnecessary, but I typically always use SMTP with the mail class. There are just too many server configuration issues that can result in mail not being sent. Sometimes anonymous (e.g. 'nobody' or 'www-data') users are restricted from using sendmail - a very common problem if the server isn't properly configured with suexec.
Additionally, using SMTP relies on known-good DNS / SPF settings of a known-working mail server - might not be the case on individual app servers that you use.
You could probably get to the bottom of the issue with a bit more digging, and possibly even get it corrected - but then you've got the same issue all over again if you need to move your app, or bring up more servers.
Just follow the email class documentation to use SMTP, which is just really a matter of changing the $config['protocol'] accordingly, then add the SMTP host / user / pass variables. Set up an email account, and give it a go. Mail forwarding settings can handle things like noreply a bit more gracefully as well.
To try it, just override the $config array in your controller, e.g.:
$myTempConfig['protocol'] = 'smtp';
$myTempConfig['smtp_host'] = 'mail.somedomain.com';
$myTempConfig['smtp_user'] = 'username';
$myTempConfig['smtp_pass'] = 'swordfish';
$myTempConfig['smtp_port'] = 25;
$myTempConfig['smtp_timeout'] = 30; // adjust as needed for busy mail servers
then call:
$this->email->initialize($myTempConfig)
so it loads the settings. You could just call it $config if you want, I just like making it clear what I'm doing when I do that.
It's really just better to rid yourself of the problem and be done with it once and for all. Once you have SMTP setup, your code just works, no matter where you put it.
Most decent hosting utilizes suexec correctly which means the mail class will 'just work' using sendmail. However, if you tend to deploy a lot of stuff with platform-as-a-service providers, or your own servers, it just makes better sense to use SMTP and save some headache and work.
I am using the following PHP CODE to send BULK MAIL .But Mails seems to Land in SPAM.I am using "phpmailer" class to send the mail.
require 'mailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "info#gmail.com";
$mail->Password = "Bexwa44Puciz"; // GMAIL password
$mail->AddReplyTo('info#gmail.com', 'Info');
$Appname = 'info.com';
$_subject="Newsletter From: ".$Appname;
$ema=",";
$to_bcc=explode(",",$ema);
$mail->AddCustomHeader($headers);
foreach($to_bcc as $tb){
$mail->AddBCC($tb, $dname);
}
$_body ="News content";//$hid;
$mail->FromName = "info.com";
$mail->From="inf#gmail.com";
$mail->Subject = $_subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($_body);
if($mail->Send()){
echo "Done";
}else {
echo "Failed";
}
I experienced same. My website sends requests for data confirmation to users a few times each day while I do my daily data maintenance. I sent a test message to my Gmail address and found that if you read your mail through Gmail webmail interface it will sometimes tell you Why the message was spammed. Very useful. It gave the reason "A lot of messages from hp19.hostpapa.com were spam". I am on a budget shared server and I assume a hundred other spammers have bought accounts on the same machine as mine and are using it for evil. My site is non-profit so buying a dedicated box to avoid spam is not an option. So...
My solution was to change my CMS to not use PHP mail() at all. Now my CMS simply displays the message and a mailto: link with Subject parameter set. Now my process is to hit CTRL+C, Click the link, CTRL+V, and hit send. Messages are sent from my computer's IP Address (not on any blacklist) using my mail client, Thunderbird.
This takes me just a couple of seconds longer than it did when my CMS used PHP mail() to send the message for me. However I have found I am receiving a lot more replies so I am happy that the vast majority of messages are not getting spam-binned.
I appreciate this manual solution is not appropriate for automated bulk messaging but for small non-profit sites on shared server who trigger each message with a click, I thought it was worth sharing.
There are a number of reasons you could be going into someones spam box. Your email server could be blacklisted due to either you, or another user on your server. You can check it at http://mxtoolbox.com/blacklists.aspx
Also check your SPF records in your DNS
How can I configure PHP to send all outgoing mail to my own account so that I can test a business application without actually sending mails to unsuspecting businesses, such as "Congratulations, you have a new account. You will be billed for $xxx" ?
Rather than configuring PHP, a generalized solution would be to stand up a dummy SMTP server.
See this question.
So you already wrote the application and it uses live email addresses, and now you want to test it? Did you use a centralized function for mail or are there tons of mail() calls all over the code? Sorry but you're going to have to change every mail() call. Do yourself a favor and replace them all with your own function, and then handle test/live functionality in that one location.
You can redirect all port 25 traffic on the server running PHP to a mailserver/port which delivers all mail to you.
This is the only 100% foolproof method of which I know.
You could create a Google Apps account (or use your dummy server), create a catch-all email account and have it sent to the domain. All you would have to do is look at the catch-all account.
I found this site: http://dummysmtp.com/.
My server is running qmail, so I edited the contents of /var/qmail/control/smtproutes like so:
:smtp.dummysmtp.com username password
It worked when I sent a simple mail with PHP mail(), but later I found that mail is still getting out to other people. I had to crawl into the bowels of the code and found this:
/* Choose the mailer */
switch($this->Mailer) {
case 'sendmail':
$result = $this->SendmailSend($header, $body);
break;
case 'smtp':
$result = $this->SmtpSend($header, $body);
break;
case 'mail':
$result = $this->MailSend($header, $body);
break;
default:
$result = $this->MailSend($header, $body);
break;
//$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
//$result = false;
//break;
}
So I had to make sure that each option was configured to send its mail to dummysmtp.com. Once I got that figured out, it all worked.
I'm trying to handle bounced message and send to a responsible System Administrator.
I use CakePHP Email Component to send the message. On server side, I use postfix to transport the message.
function sendAsEmail($data) {
$Email->sendAs = 'html';
$Email->from = $user['Sender']['username'] . '#example.com';
$Email->return = Configure::read('App.systemAdminEmail');
$Email->bcc = array($data['Message']['recipient_text']);
$content = 'Some content';
$Email->send($content);
}
As you can see above, I set the $Email->return to sysadmin's email which it will send all the bounced message.
On postfix configuration, I tried creating a bounce.cf template and set bounce_template_file. http://www.howtoforge.com/configure-custom-postfix-bounce-messages
How do I get the bounced message and send it to System Administrator?
I think what you'll need to do is to use an SMTP (or I suppose POP3) connector for PHP. Then you'll basically have to create your own PHP email client that will login to the server, ask for the messages that have been bounced, and parse them appropriately.
I would think there would be a CakePHP component for this, but I can't find one.
I would recommend that you use an Envelope Header in your email. Otherwise you'll be stuck trying to parse the recipient server bounce, and those are very very inconsistent. If you use the VERP (variable envelope return protocol?) header, you can encode a unique hash into the email address which should be really easy to parse out in your PHPEmailClient.
More info on VERP: http://en.wikipedia.org/wiki/Variable_envelope_return_path
Cake-specific VERP stuff: http://www.mainelydesign.com/blog/view/setting-envelope-from-header-cakephp-email-component
I also highly recommend that you look into using SwiftMailer. It has a lot of plugins; you might find a base PHP SMTP client that you can easily modify to do what you need. http://swiftmailer.org/