We send emails in plain text from PHP using CodeIgniter (v1.7) and also PHPMailer (v5.1). Current production setup uses a cheapie SMTP relay, plan is to switch to a CritSend or SendGrid. We are testing the options now from a Rackspace Cloud server.
When we use SendGrid SMTP all "\r\n" newlines in the emials end up being doubled up, so end up as "\r\n\r\n".
All works fine when using CritSend SMTP and also two other SMTP servers.
SendGrid tech support don't think it is anything to do with their system, but have heard of another client with the same issue and apparently it got solved with a config change on the client's side.
Anyone experienced this?
This isn't critical for us as CritSend works well and seems as good as SendGrid on features, so we will go with them. BUT being a curious type, I just can't let this go :-)
Usual setup: PHP script -> sendmail/Postfix -> external SMTP relay -> ....
To test the different SMTP relays I change the postfix config, only SendGrid gives the extra newlines all other SMTP options work fine. If I dump the email via CodeIgniter email class debug function it looks fine before it goes to postfix.
Alternate setup: PHP script (either CI mail class or PHPMialer) -> external SMTP relay -> ....
To test the different SMTP relays I change the SMTP settings in the CI email config or PHPMialer config. Only SendGrid gives the extra newlines all other SMTP options work fine.
There aren't all that many options to play with as far as I can see. I tried "utf-8" and "ISO-something or other", all newlines on our side are "\r\n"...... seesm like some very obscure bug somewhere.
Any ideas?
OK, a bit more experimenting and these settings make plain text emails go trough SendGrid nicely from PHPMailer:
$mailer->CharSet = "utf-8";
$mailer->LE = "\r\n";
$mailer->Encoding = "quoted-printable";
$mailer->WordWrap = 80;
The "quoted-printable" part is the key.
What worked for me was using actual line-breaks in the PHP text as follows:
// Prepare email
$email = array(
'api_user' => App::emailAPIUser(),
'api_key' => App::emailAPIPwd(),
'to' => $email,
'subject' => 'Thank you for entering ' . App::name(),
'html' => $email_body,
'text' => '
Thank you for entering Competition.
You are now in the running to WIN your prices valued at $6000.
Winners will be notified of their status by the 14th February 2012.
Good luck!',
'from' => 'competitions#company.com'
);
Related
the gmail smtp-relay works fine using the sync driver, but if we queue the email we this error. cleared config, cache, & restarted queue workers. tested in prod and dev, same results
[2021-01-24 20:04:22] production.ERROR: Expected response code 250 but got an empty response {"exception":"[object] (Swift_TransportException(code: 0): Expected response code 250 but got an empty response at /home/****/****/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:448)
were wondering is this because of serialization and something is not making it through that process???
using latest stable release of laravel >8.0. gmail smtp is authenticating just fine, per why the sync driver sends emails easily. maybe there needs to be a timeout on the queue jobs so they dont barrage gmail so quickly? also our code works fine using sendgrid for example as the smtp relay. thanks.
See https://laracasts.com/discuss/channels/laravel/laravel-swift-mailer-exception-expected-response-code-250-but-got-an-empty-response-using-gmail-smtp-relay-database-queue-driver
Update your AppServiceProvider.php
add this inside boot();
// Fix for SwiftMailer Service;
$_SERVER["SERVER_NAME"] = "your.domain.name";
For users of smtp-relay.gmail.com, if you use localhost/127.0.0.1 as domain during developments, you probably need to change the domain name to use in EHLO command to begin the transaction. I solved this by adding &local_domain=dev.mydomain.tld at the and of my DSN.
smtp://smtp-relay.gmail.com:587?encryption=tls&local_domain=dev.mydomain.tld&...
For SwiftMailer Symfony bundle (since 2.4.0), you can set the local_domain config parameter:
// config/packages/dev/swiftmailer.yaml
swiftmailer:
...
local_domain: dev.mydomain.tld
Explanation for the 2 previous Answers
if $_SERVER["SERVER_NAME"] is the solution:
When you are using cron
The reason is that $_SERVER["SERVER_NAME"] is null when cron is executed. $_SERVER["SERVER_NAME"] is usually only defined for http access.
Example implementation (laravel):
if (!isset($_SERVER['SERVER_NAME'])) {
$url = config('env.APP_URL');
$domain = mb_ereg_replace("http(s)? ://", "", $url);
$domainParts = explode('/', $domain);
ini_set('server_name', count($domainParts) > 0 ? $domainParts[0] : $domain)
}
References :
Cron Job $_SERVER issue
https://github.com/swiftmailer/swiftmailer/issues/992
if 'local_domain' is the solution
When you have a mailhost setting of MAIL_HOST=smtp-relay.gmail.com in your laravel project
The reason is that if local_domain' is not set, the protocol for mail communication with Gmail will be EHLO [127.0.0.1]` and the communication will be disconnected.
By the way, I used gmail->gmail alias and did not need relay in the first place, so I solved the problem by setting MAIL_HOST=smtp.gmail.com.
References:
https://blog.trippyboy.com/2021/laravel/laravel-expected-response-code-250-but-got-an-empty-response/
I had to deal with both of them because of cron messaging and MAIL_HOST=smtp-relay.gmail.com in my environment.
I hope this information will help you.
I have several websites that use SwiftMailer with Gmail. I haven't touched any of these sites' code, and suddenly all of them no longer work, resulting in Fatal errors: Connection could not be established with host smtp.gmail.com [ #0]
I've searched all over the internet for what may cause this, tried several solutions, but nothing works. Does anyone know if something either changed on Gmail's end (they no longer allow me to connect?) or what else could have happened?
Some things I tried:
open ports on server router (465 for SSL) - didn't help
disable firewall on server - didn't help
try the IP-address of smtp.gmail.com in stead of the domain name, using ping to find out the IP - didn't help
changing settings in the SwiftMailer program (setting certain verification options to false) - didn't help
I know this isn't a very concrete coding question, but I haven't changed anything to my code so the problem literally cannot be in my code. I'm just hoping someone knows what changed 2-3 days ago, and what I need to do to make SwiftMailer work again.
Note: the Gmail accounts' passwords or account security settings such as 2-step verification and sorts also didn't change. Also, using a different SMTP such as the one from GMX.net, the script still works just fine!
Strange hm?
I had the same issue today. I succesfully tried the workaround mentioned in this web.
Something has been changed in Gmail config. I will try a better solution but in the mean time will use this workaround.
Hope it help.
https://github.com/swiftmailer/swiftmailer/issues/544
You could disable the SSL check by modifying the function
"_establishSocketConnection" in StreamBuffer.php. Add these lines
before stream_socket_client command:
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
I would highly recommend you look into the logging plugin.
https://swiftmailer.symfony.com/docs/plugins.html#logger-plugin
It is likely to be already installed so all you need to do is follow the instructions in here and if you run the logger it will give you reasons why the email is failing.
While Toni's solution works it requires fiddling around with vendor source which is not ideal. You can also set the stream options programmatically in your code, where you use the swiftmailer $mailer instance, e.g.
$transport = $mailer->getTransport();
if($transport instanceof \Swift_Transport_EsmtpTransport){
$transport->setStreamOptions([
'ssl' => ['allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false]
]);
}
I'm trying to get a Typo3 (6.2) instance running behind a (forwarding) proxy (squid). I have set
'HTTP' => array(
'adapter' => 'curl',
'proxy_host' => 'my.local.proxy.ip',
'proxy_port' => '8080',
)
as well as
'SYS' => array(
'curlProxyServer' => 'http://my.local.proxy.ip:8080',
'curlUse' => '1'
)
The proxy doesn't ask for credentials.
When I try to update the extension list, I get the error message
Update Extension List
Could not access remote resource http://repositories.typo3.org/mirrors.xml.gz.
If I try Get preconfigured distribution, it says
1342635425
Could not access remote resource http://repositories.typo3.org/mirrors.xml.gz.
According to the proxy log, the server doesn't even try to connect to the proxy.
I can easily download the file using wget on the command line.
Ok, I've investigated he issue a bit more and from what I can tell, the Typo3 doesn't even try to connect anywhere.
I used tcpdump and wireshark to analyze the network traffic. The site claims to have tried sending a http-Request to repositories.typo3.org so I'd expect to find either a proxy connection attempt or a DNS query followed by an attempt to connect to that IP. (Of course, the latter is known not to work.) However, none of this happens.
I've tried some slight changes in the variable curlProxyServer. The documentation clearly states
String: Proxyserver as http://proxy:port/. Deprecated since 4.6 - will be removed in TYPO3 CMS 7. See below for http options.
So I tried adding the trailing "/" and removing the "http://" - no change. I'm confident there's no problem whatsoever regarding the proxy as the proxy isn't even contacted and has been working perfectly fine for everything else for years.
The error message comes from \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper::fetchFile(). This one uses \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl() to get the actual file content.
According to your setting, it should use the first part of the function, because curlUse is set and the URL starts with http or https.
So what you would need to do now is to throw some debug lines in the code and check at what point the request goes wrong.
Look at the source code, three possibilities come to mind:
The curl proxy parameters does not support a scheme, thus it should be 'curlProxyServer' => 'my.local.proxy.ip:8080',.
Some redirect does not work.
Your proxy has problems with https, because the TYPO3 TER should be queried over https.
I have Laravel 5.2 fresh installation.
I did following:
I have set up my .env file
MAIL_DRIVER=mandrill
SECRET=my_mandrill_api_key
I have installed Guzzle (https://github.com/guzzle/guzzle)
I have setup my email in view (https://github.com/laravel/laravel/blob/5.0/resources/views/emails/password.blade.php)
I have fixed the certificate issue (PHP cURL error code 60)
So it seems everything is done correctly.
When I fill email to reset password and press Send Password Reset Link button, I get following error
Server error: POST
https://mandrillapp.com/api/1.0/messages/send-raw.json resulted in a
500 Internal Server Error response:
{"status":"error","code":-1,"name":"ValidationError","message":"You
must specify a key value"}
I have check my log in Mandrill (https://mandrillapp.com/settings/api) there is no logs for my action.
From the error of Mandrill, I know it does not get the api key, so for some reason the api key and other values is not passing over to Mandrill api.
Question: What is missing/wrong?
Note: right now I am working on my local environment building the app. My local environment Windows 10/Bitnami WAMP stack 7/ I am also using Mandrill API.
If you are using the Mandrill driver then you must set the MANDRILL_SECRET in your .env file.
The other settings MAIL_HOST, MAIL_PORT and so on are for use with other drivers.
See the documentation here about using the Mandrill driver. It mentions that you should set the Mandrill key in config/services.php but you should really set that using an environment variable, so if you have customized the file change it back to
'mandrill' => [
'secret' => env('MANDRILL_SECRET'),
],
Then you will be able to read the MANDRILL_SECRET value from the .env file.
So in your .env file you'll have;
MAIL_DRIVER=mandrill
MANDRILL_SECRET=your_mandrill_key_here
I currently have a contact form on my website which sends off an email notification upon submission. It is working perfectly on my end and even when I send it externally to friends as a test they are receiving it.
My client however, who is in France, can't seem to receive this email at all and I have no idea why. Is there anything I need to do to ensure that they receive it? I thought it was something on their end but they're absolutely adamant that it's not and that it's a problem with my code. I have tried different email addresses for them with different domains and still no luck!
$this->load->library('parser');
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$this->load->library('email');
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'email' => $this->input->post('email'),
'phone' => $this->input->post('phone'),
'message' => $this->input->post('message')
);
$body = $this->parser->parse('html_email', $data, true);
$this->email->from('test#test.com', 'Duparc');
$this->email->to('test#test.com');
$this->email->subject('Test Email');
$this->email->message($body);
$this->email->send();
In my opinion the problem does not originate from CodeIgniter. Assuming the mail did not went into a spam box, your customer's provider is probably dismissing your message for some other reason. One reason I can immediately think of is that you are probably trying to send a message from a domain (e.g. test.com) you're not allowed from. My advise is starting to try sending an email with another tool to your french customer (any sendmail or postfix client tool) and to see if he do receive it.
If that succeeds, then the problem probably comes from your forged email (therefore try using a valid domain name). Sometimes removing it completely will work too (it might then be replaced by the external IP).
If not, then the problem comes from your web server's config. I had this problem using postfix where I had to explicitly set the "General Options" > "What domain to use in outbound mail" configuration option to my domain name in order to be accepted by a capricious server which silently dismissed our mail.
If nothing is working, you might also use another mail server which might luckily fix the issue. Here is the code I used to force CodeIgniter using sendmail instead:
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$this->email->initialize($config);