Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SarahS's avatar
Level 12

PHP Mail settings

I have a basic PHP contact form on one page. It doesn't do much and the basic send code is this:

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $headers) or die ("Failure");

However, it has some problems sending to Gmail accounts (but others seem fine). My host says that I need to change the server, port, encryption and authentication but I have only ever seen that done in the php.ini, but I cannot edit that. Can I change these settings in my PHP code? Thanks.

0 likes
5 replies
bobbybouwmann's avatar

You're using the basic PHP mailer method. This method is only for really simple cases of sending emails. It doesn't allow for setting the encryption and so one

If you're using a framework like Laravel, it uses different libraries to send emails. They are better prepared for this kind of thing. Any reason for now using the Laravel Mailer class in your case?

SarahS's avatar
Level 12

It's a shared hosting environment so plain PHP is pretty much all I can do. It was just so someone could have a quick contact form and nothing else so I didn't want to spend too much time on it.

Is it possible to have these settings in the code or does it need to be in the php.ini file?

bobbybouwmann's avatar

Shared hosting these days can easily run composer packages. Instaling that package or installing Laravel as a framework should work just fine.

SarahS's avatar
Level 12

So basically the answer is no, I cannot add those settings in the code?

Please or to participate in this conversation.