I need to send mail from PHP code, I am using XAMPP (windows) for PHP. I use mail() like this:
Here is my code 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#gmail.com
My PHP code:
if(mail("email#gmail.com",$subject,$message))
{
echo "mail sent";
}
else
{
echo "error";
}
I get the message 'mail sent' but did not receive an email. What am I doing wrong?
Use smtp.gmail.com as smtp host and set port to 587, you will also need to set up authentication and for that reason I'd suggest using something a bit more advanced than the native mail function; examples are PEAR's Mail package, SwiftMailer or PHPMailer.
You are using gmail to send email then you should configure gmail POP settings...
In general you need to have SMTP Server configured on server.
You've set up this smtp server: "localhost:25". Do you have some SMTP-server running on this port on your local machine?
If you want to send emails from local machine you should either setup some SMTP-server locally (but this is not simple) or use some remote SMTP-gateway. Google for it.
Upd. Anyway this is duplicate
How to configure XAMPP to send mail from localhost?
Related
I need some help. I am trying to send an email from a php script. My environment comprises of the following:
Operating System: Windows 8
XAMPP version: 1.8.2
php version: 5.4.19
I have the following php script:
<?php
mail('sugar.donkey#gmail.com','Helo','This is a test','From:salt#goodness.com');
?>
The following configuration on send mail configuration file:
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=465
auth_username=sugar.donkey+gmail.com
auth_password=[MYPASSWORDHERE]
The configurations on php.ini:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = smtp.gmail.com
; smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster#localhost
I dont get error when I run the php script, but I also dont seem to receive an email. Where am I going wrong ?
I am not sure what os you are running on your webserver, however;
Most Linux installations have sendmail preinstalled, there is always a hassle of setting up SPF/PTR records, to ensure that the email sent by your PHP script is not flagged as spam. A SMTP client called MSMTP can be used to send emails using third-party SMTP servers, this can also be used by PHP's mail() in the place of sendmail.
I hope this helps
https://www.digitalocean.com/community/articles/how-to-use-gmail-or-yahoo-with-php-mail-function
Also for localhost testing, check this out.
http://blogs.bigfish.tv/adam/2009/12/03/setup-a-testing-mail-server-using-php-on-mac-os-x/
Even I am trying to get this configuration work :)
in your case i believe you need to comment out in php.ini
the configuration should be
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
http://php.net/sendmail-from
sendmail_from = postmaster#localhost
Thank you
Here's what's in my php.ini file:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Is it possible to simply change localhost to smtp.live.com and change the port (smtp_port) to point to a different port (specifically, 567, as required by Microsoft) in order to send email to a Microsoft Live email address via PHP? I tried the normal mail() route, but I never received the email from the script, and can only assume it has to do with SMTP authentication. I don't have very much experience with PHP.
No, that won't work. smtp.live.com requires authentication, and the PHP mail() command does not support authentication. As Pascamel suggested, you should use a library that supports sending mail through a remote SMTP server using authentication. phpmailer is very good.
Have a look at PHPMailer : https://github.com/PHPMailer/PHPMailer
I'm using it to send emails through a GMail account, settings are pretty easy!
This way you won't have to update your php.ini
in php.ini you can change smtp server to different server ONLY for WINDOWS machines.
You can't do it for unix machines. it just ignores even if you set smtp = yourserver.
I have config gmail as a local SMTP mail client. I have use host as smtp.gmail.com, my gmail address as username and its password and 587 as port. But i didnt see any emails send from. I have also uncomment the following lines in php.ini
[mail function] For Win32 only.
http://php.net/smtp SMTP = localhost
http://php.net/smtp-port smtp_port =
587
; For Win32 only.
http://php.net/sendmail-from
sendmail_from = myemail#gmail.com
What am i missing please? I am using windows7 x64. I have notice the php.ini says for windows 32 only? is there a another settings for windows x64?
Thanks.
here you have got full tutorial explaining how to achieve this
http://digiex.net/guides-reviews/guides-tutorials/application-guides/544-configuring-php-under-windows-use-gmail-external-smtp-server-ssl.html
there is also great class that I'd recommend for sending e-mails PHPMailer:
tutorial here
When i send mail php from my server it works fine.But when i placed the code in my client server.it shows mail sending failed.what is the problem.
Your PHP server does not configured for mail. Basically mail function uses sendmail on UNIX systems. But for Windows it's remain unconfigured. You need to configure from PHP.ini file.
For example:
[mail function]
; For Win32 only.
SMTP = smtp.live.com
smtp_port = 25
username = my mail
password = my pass
I use the latest WAMP and I get this when I try to send emails:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\main\createaccount.php on line 8
Message delivery failed...
The message:
$to = "xxx#hotmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
Do you need do download a "mailserver" also?
Please help.
This works for me and should work for you: Use Fake Sendmail and a webhost mail server (i.e. - Godaddy, 1and1, etc.).
1.) Download the sendmail zip and extract it to C:\Wamp\bin\sendmail (for purposes of this example).
2.) Edit C:\wamp\bin\sendmail\sendmail.ini and set the following to your mail server's requirements (mine are below):
smtp_server=mail.yourdomain.com
smtp_port=26
smtp_ssl=none
;default_domain=yourdomain.com
auth_username=smtpuser#yourdomain.com
auth_password=smtppassword
;pop3_server=
;pop3_username=
;pop3_password=
;force_sender=
;force_recipient=
3.) Set the path of sendmail.exe in your php.ini file.
[mail function]
; For Win32 only.
SMTP =
; For Win32 only.
sendmail_from =
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\wamp\bin\sendmail\sendmail.exe -t"
4.) Restart Wampserver.
You might have success using Gmail, but there are a few extra tweaks to make it work. I prefer using the mail server of the webhost where I upload my code.
You are not running an smtp server on your machine, but you don't have to. Just set SMTP to a open smtp server for example:
ini_set('SMTP', 'smtp.yourisp.com');
Take a look at your ISP's home page or http://www.e-eeasy.com/SMTPServerList.aspx for list of SMTP servers.
If you have a desktop mail program, you can use the same address as you use for outgoing mail.
I think your mail server (SMTP) outgoing mail server is not configured in your php.ini file.
Have a look at this:
http://email.about.com/od/emailprogrammingtips/qt/Configure_PHP_to_Use_a_Remote_SMTP_Server_for_Sending_Mail.htm
Also hotmail doesn't allow you to use their mailservers. You should use yahoo or gmail.
Are you sure these servers have a mail program installed on them? If not, that's your problem. For example, XAMPP comes with a mail program called Mercury which you must start before you can send mail through the server.
Follow this article, it works if you have a gmail account.
or at least any email account in which you know the server, port and this stuff.
Send Email From localhost
here is another solution - WAMP send Mail using SMTP localhost
KEEP IN MIND, everytime, after You change php.ini,
you must restart wamp (! ! !)
p.s. in php.ini, i have used:
SMTP = localhost
smtp_port = 25
sendmail_from = your_user#gmail.com
or if oyu cant edit php.ini, try to insert these lines in your php script.
ini_set("SMTP", "localhost");
ini_set("smtp_port", "25");
ini_set("sendmail_from", "your_user#gmail.com");