I have configured aws's ses service but have not been able to use it. My emails are being sent but they are sent through my hosting server (Godaddy) and I would want to send them only through AWS's SES. Pardon me, if I have made a rookie mistake.
Here's what my code looks like
<?php
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 2;
$mail->Host = 'email-smtp.eu-west-1.amazonaws.com';
$mail->Port = 25;
$mail->ssl = true;
$mail->authentication = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->setFrom('vaibhav#zigsaw.in', 'Test Email');
$mail->Body = 'Test Email from Zigsaw';
$mail->AddReplyTo('zigsawconsultancy#gmail.com', 'Candidate');
$mail->addAddress('zigsawconsultancy#gmail.com', 'Recruiter');
$mail->Subject = 'Test Email from Zigsaw';
if(!$mail->send())
{
echo "Email not sent. " , $mail->ErrorInfo , PHP_EOL;
}
else
{
echo "Email sent!" , PHP_EOL;
}
?>
Disclaimer: My file is hosted on a godaddy server and I am trying to send emails through AWS SES.
GoDaddy blocks outbound SMTP, but you've not told PHPMailer to use SMTP (so most of your settings do nothing), so it's submitting via the mail() function, using a local mail server, which in GoDaddy's case is their server - so that's why it's going that way. Unfortunately there isn't a way of using external SMTP on GoDaddy, though you can send via their secureserver.net relay - but that of course means you can't send using your personal domain because it's forgery and you messages will be spam-filtered or bounced.
If you call:
$mail->isSMTP();
PHPMailer will use SMTP and your other settings, though as I said in my comment, you've just invented a bunch of things that will not work, so rewrite your code based on the examples provided, though this won't work on GoDaddy.
If SES has an HTTP API, so you may be able to use that instead, since it will not be subject to GoDaddy's blocking.
Related
I have used the following PHP code to send email, but when I login to the gmail account after sending an email, the email that has sent is not recorded in the sent mail section of gmail. But emails are successfully delivered each time. I can use the IsSMTP() function in my laptop and in that case sent mails are recorded, but in GoDaddy VPS I can not use IsSMTP() but to use IsMail().
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\OAuth;
use PHPMailer\PHPMailer\POP3;
require '../PHPMailer/Exception.php';
require '../PHPMailer/PHPMailer.php';
require '../PHPMailer/SMTP.php';
require '../PHPMailer/OAuth.php';
require '../PHPMailer/POP3.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->IsMail();
//$mail->IsSMTP(); // if enabled instead of IsMail() an error "can not connect to SMTP" appears.
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'username#gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
//Recipients
$mail->setFrom('username#gmail.com', 'OFFICE');
$mail->addReplyTo('username#gmail.com', 'OFFICE');
$mail->addBCC("username#gmail.com", "OFFICE");//since sent mails are not saved
$mail->isHTML(true);
$mail->addAddress('to#gmail.com');
$mail->Subject = 'Subject';
$mail->Body = 'Hello';
$mail->AltBody = 'Hello';
$mail->send();
The problem is that Godaddy (and many other VPS providers) block SMTP ports in order to fight spammers.
When you are using $mail->IsMail(), the e-mails will go via GoDaddy's servers completely bypassing your Gmail account.
Now there is another problem as well, Google protects your #gmail.com addresses using various methods (such as SPF), so even if you are able to send the e-mail, it will be most likely marked as SPAM - if delivered at all. Otherwise anyone could send e-mails as you..
I'd highly suggest purchasing a domain (if you dont have one already) and either:
Hosting it in GoDaddys e-mail service and sending it via their SMTP servers (their SMTP servers are allowed)
Use external service which does not rely on SMTP (such as MailGun and their PHP SDK for example, but do your own research for a suitable one)
There might be some other "hacky" ways to still send these e-mails trough Gmail if you really need to, such as using VPN inside VPS or[1] proxying google SMTP externally on some other port which is not blocked. Beware, these methods still require some external service (most likely paid) and might conflict with GoDaddy's and/or Gmail TOS
[1] Apparently most of the VPN providers also block SMTP ports to avoid e-mail spammer flood
How can i use proxies to send smtp mails using PHPmailer?
The proxy format is: proxy/port/user/password
I am using following code to send email:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'C:/xampp/php/pear/PHPMailer-master/src/PHPMailer.php';
require 'C:/xampp/php/pear/PHPMailer-master/src/SMTP.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "test#gmail.com";
$mail->Password = "password";
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->From = "test#gmail.com";
$mail->FromName = "Name";
$mail->addAddress("address#yahoo.com", "name");
$mail->isHTML(true);
$mail->Subject = "Mail Subject";
$mail->Body = "Something";
$mail->AltBody = "This is the plain text version of the email content";
try {
$mail->send();
echo "Message has been sent successfully";
} catch (Exception $e) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
I tried with socat had no success since socat cannot be installed on my server,i also tried with curl but had no success.
I'm also aware that phpmailer has no explicit SMTP proxy support.
Also guide me if there is a substitute for PHPMailer that can use proxy, in case proxies can't be configured for PHPMailer.
I suspect this is the same question as was asked on GitHub recently.
The short answer is that you can't. Not because PHPMailer doesn't support it, but because proxying SMTP doesn't really exist in any practical sense because of its disconnected, async, store-and-forward nature. It's completely unlike HTTP in this respect. You have two alternatives:
Use a TCP proxy. You specify the proxy host IP as your mail server, and it forwards the traffic. This is completely transparent to PHPMailer, and so does not require any specific support, but you are likely to run into TLS issues.
Use an SMTP relay. Send to a "nearby" mail server (usually referred to as a "smarthost") which then deals with onward delivery for you. This is probably what you want. Again, PHPMailer doesn't care about your relaying arrangements here as you simply deliver to the smarthost as usual, so no specific support is required.
The reason an "SMTP proxy" can't really work is because there is no guarantee that an SMTP server can make an onward delivery. It may require literally days of waiting and retrying to deliver a message, and this means that the proxy needs to implement everything an SMTP server does, turning it into an SMTP relay.
There are SMTP proxies, but they are typically only ever used in high-availability environments, such as in SMTP front-end load balancers, where immediate onward delivery is essentially guaranteed to be possible, so the proxy needs no local storage or queuing abilities. That's probably not what you're looking for.
If you want more than that you need to say exactly what it is you're trying to achieve, why, and how.
I am stuck trying to make PHPMailer to work with my website hosted on Siteground.
I installed it by composer via PuTTY, everything looking fine so far:
But when I try to test it, I can't get it to work properly.
Here is a sample of my testing code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = '**HOST**';
$mail->SMTPAuth = true;
$mail->Username = '**MAILACCOUNT**';
$mail->Password = '**PASSWORD';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->setFrom('**MAILACCOUNT**', 'Mailer');
$mail->addAddress('**TESTMAILRECIPIENT', 'test');
$mail->isHTML(true);
$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}";
}
?>
Which is a modified version of the template PHPMailer provides on their github.
All of my credentials are good (host, mail account, password). I tried with different ports (25, 587) and as per Siteground the good port for SMTP is 465. But nothing work. The try catch block does not even catch any error, sometimes depending of what I try my webpage stays blank, or return a HTMLERROR 500.
I tried to reach out their technical support but they don't seem to have a clue about anything. They sent me the link to the PHPMailer github, telling me to follow the tutorial.
There is absolutely no documentation about using this PHP library with their services. I have been searching for 2 days now. It seems they have changed their interface, as many - if not all - of their tutorials are for an older version of their cPanel.
Maybe it could have something to do with SPF and DKIM protocols? DKIM is active on my account, SPF I have absolutely no clue what to do with this.
Here is my generated SPF record, if ever you need to know:
v=spf1 +a +mx +ip4:**MYIP** include:_spf.mailspamprotection.com ~all
I tried many online tutorials and adapted them to my needs with Siteground, with no success.
Is there anybody used to their system and could help me getting this to work?
I use a shared hosted plan, if it helps. They use Linux servers.
Thank you very much!
Just in case someone is looking for the same thing - for me what worked is the next:
prefixing the host with "ssl://"
in PHPMailer instance setting:
$mail->SMTPSecure = false;
$mail->SMTPAutoTLS = false;
Also the port I used was 465.
Very strange combination of settings, but at least it worked in my case.
Below is the phpmailer code which I am using :
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = as given in the configure mail client window;
$mail->SMTPAuth = true;
$mail->Username =as given in the configure mail client window;
$mail->Password = as given in the configure mail client window;
$mail->SMTPSecure = 'tls' ;
$mail->Port = 465;
$mail->setFrom('my email', 'my name');
$mail->addAddress('email', 'name');
$mail->isHTML(true);
$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;
}
The page keeps loading and the e-mail is not sent,What is happening ? and how should I configure this . I am using godaddy cpanel.
You're using SMTP to localhost (which is the recommended and usually the fastest sending mechanism, as far as your script is concerned), but you've enabled encryption and authentication, so your local mail server will need to present a valid certificate for localhost, which is not going to happen. It's usually unnecessary to use encryption or authentication when sending to localhost, because you can whitelist localhost as the source, and this will make it even faster.
If you set SMTPDebug = 2, you can look at the timestamps in the SMTP conversation and see which part is taking a long time.
Keepalive won't help unless you're sending lots of messages in quick succession.
It may also help to look in your local mail server's logs and see if there's anything interesting in there.
You're also using a very old version of PHPMailer; get the latest, and base your code on the examples provided.
You should have no trouble submitting a few hundred messages per second.
If your problem is that submission is fast, but ultimate delivery is slow, you need to look at your local mail server logs for why that is. You may be getting delivery deferrals.
Well, i am having an issue that i really don't have any clue and already have read everything that i could find about.
I have a code in php using phpMailer that using gmail, the emails arrives where they should when the php archive is opened by the terminal, but, when i upload to the server the emails just arrive at the final destiny if they never arrive at the mail.
in my case i want to send to an email exemple#companyName.io, that is a gmail email as well.
i just cant figure it out why the emails just work arriving at the final destiny when they are being send to a hotmail or gmail account(exemple#gmail.com) but to a exemple#companyName.io(that is a gmail as well) does not work.
Thanks in advance!
PHP code:
<?php
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587; //same problem with other ports
$mail->SMTPSecure = 'tls'; //same problem with ssl
$mail->SMTPAuth = true;
$mail->Username = "exemple#gmail.com";
$mail->Password = "password";
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$message = strip_tags($_POST['message']);
$mail->setFrom($email, $name);
$mail->addAddress('exemple#CompanyName.io', 'exemple Name');
$mail->Subject = 'Contact';
$mail->Body = $message;
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
EDIT:
i found out the answer, my server was from godaddy, so :
GoDaddy
Popular US hosting provider GoDaddy imposes very strict (to the point of becoming almost useless) constraints on sending email. They block outbound SMTP to ports 25, 465 and 587 to all servers except their own. This problem is the subject of many frustrating questions on Stack Overflow. If you find your script works on your local machine, but not when you upload it to GoDaddy, this will be what's happening to you. The solution is extremely poorly documented by GoDaddy: you must send through their servers, and also disable all security features, username and password (great, huh?!), giving you this config for PHPMailer:
$mail->isSMTP();
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = 25;
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
GoDaddy also refuses to send with a From add
ress belonging to any aol, gmail, yahoo, hotmail, live, aim, or msn domain (see their docs). This is because all those domains deploy SPF and DKIM anti-forgery measures, and faking your from address is forgery.
You may find it easier to switch to a more enlightened hosting provider.
I guess you are missing IsSMTP() setting:
$mail = new PHPMailer();
$mail->IsSMTP();