How to send email using php mail function and what are the php.ini settings needed?

Hi,

I’m new to PHP.
I need to send email without providing any password in settings. First of all is this possible?

If possible, what are the settings needed to be done in php.ini and in any other settings required?

I have my php script as below :


<?php
echo "Hello World!";

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","587");

$to_email = '[email protected]';
$subject = 'Testing PHP Mail';
$message = 'This mail is sent using the PHP mail function';
$headers = 'From: vidhyajsv@gmai\r\n';
$headers .="Content-type: text/html\r\n";
mail($to_email,$subject,$message,$headers);

And i’m getting below error when I execute php script.

Warning: mail(): Failed to connect to mailserver at "ssl://smtp.gmail.com" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp64\www\emailapp\index.php on line 18.

Please help me on this.

If you want random people to send spam under your email-adress… yes, But i don’t think Google would allow that.

Thanks for your comments.
For testing purpose i used gmail… otherwise i think it would be customer’s organization mail server. It can go to spam also. That’s fine.
Is this possible ?
I’m using wamp server 3.1.9. Can’t i test it locally in development environment?

My requirement is to send email without authentication. Also It should be by Using php mail function. I Should not be using any other library.

What are the settings needed for this?
I’m getting error as previously mentioned.
Im not sure if I’m missing something.

You need a mail server running locally for that, or you need to point to a mail server in you ini that will allow anonymous calls. When on a hosted server, that will already be configured, so if you are going with the mail function, which i don’t recommend to anyone, it will work when it is on the server.

Sponsor our Newsletter | Privacy Policy | Terms of Service