Reputation: 2988
I am new at php. I was trying to send mail from php using this code.
<?php
$to = '[email protected]';
$subject = 'The subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I have change settings in php.ini
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]
& in sendmail.ini
# A freemail service example
account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from [email protected]
auth on
user [email protected]
password xxxxxxxxx
# Set a default account
account default : Gmail
Now code runs successfully but I am not getting any mail.
Upvotes: 15
Views: 70457
Reputation: 1
I had this issue the past weeks, on my centos boxes, sharing this for others also having issues with mail() in php not sending... This resolved the issue for all of my mail() php scripts.
// Enable the sendmail in selinux
setsebool -P httpd_can_sendmail 1
// Add the following to /etc/postfix/main.cf
relayhost = smtp.server.com
// Then from command line
service postfix restart
Upvotes: 0
Reputation: 31
Here's the link that gives me the answer:
Install the "fake sendmail for windows". If you are not using XAMPP you can download it here: http://glob.com.au/sendmail/sendmail.zip
Modify the php.ini file to use it (commented out the other lines):
mail function
For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25
For Win32 only.
sendmail_from = <e-mail username>@gmail.com
For Unix only. You may supply arguments as well
(default: "sendmail -t -i").
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
(ignore the "Unix only" bit, since we actually are using sendmail)
You then have to configure the "sendmail.ini" file in the directory where sendmail was installed:
sendmail
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=<username>
auth_password=<password>
force_sender=<e-mail username>@gmail.com
Upvotes: 0
Reputation: 806
You won't have SMTP server installed by default so you can't send emails from localhost directly. Either you can set up SMTP server on local or use third party SMTP servers. Have a look at http://www.mittalpatel.co.in/php_send_mail_from_localhost_using_gmail_smtp which gives you insight about how to send mail from localhost using third party SMTP server.
Upvotes: 3
Reputation: 570
Try to set below things in your php.ini,
OR you can set this option using php script also,
// Please specify your Mail Server oR other mail server which you are going to use.(e.g gmail, yahoo)
ini_set("SMTP","mail.YourDomain.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
Upvotes: 0
Reputation: 5139
You must change the php.ini file:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = you@yourdomain
It won't work if localhost is set, for that reason change to your mail server.
Upvotes: 4
Reputation: 1560
Your server does not have local mailserver.
There are few solutions:
Upvotes: 0
Reputation: 271
The function will not work on your localhost, as the locahost doesn't works as a SMTP server, upload your content to a valid server with SMTP installed, and then go for the mail call.
Upvotes: 1