Ive been trying desperately all day to get an email sent from a php file running on xampp from a gmail account.
I want to use Gmails SMTP as I tried forever to get Mercury to work and it was very problematic. So far I set it up as described below:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
smtp_ssl=auto
auth_username=justinharr6#gmail.com
auth_password=*password*
force_sender=justinharr#gmail.com
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header = Off
(everything else commented out)
Keep in mind this is one of many configurations I have tried none of which work. My php files is returning true from the Mail call but its never getting to the destination. Any help would be greatly appreciated.
i am assuming you are trying to send a mail through local host
i suggest you should use PHP mailer class
Related
I'm trying to send emails from my localhost, but I'm running across an issue that keeps coming up. I found this answer which explained how to set up XAMPP to send email, and the emails are sent, but when I try changing the From header, nothing happens. The email gets sent, but it's sent from my personal email.
I tried removing both the sendmail_from in php.ini and force_sender in sendmail.ini, but neither worked. I tried adding the -f parameter to the mail function, and it didn't work. I've even tried restarting XAMPP several times, but still nothing. Is there something I've overlooked or is there no way to do this?
PHP
<?php
$headers = "From: Joe Smith <joe#joesmith.com>" . "\r\n";
mail("recipient#gmail.com", "This is a test message", "Yup, it's a test message all right.", $headers, "-f joe#joesmith.com");
?>
php.ini
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from =
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=mypersonalemail#gmail.com
auth_password=mypersonalpassword
It is because you are using Google's SMTP servers and they don't allow changing the 'From' header.
This was answered here:
How to change from-address when using gmail smtp server
I just did a project similar to this. Depending on your needs, you can use PHPMailer to change your "reply to" address. Although it's not the same as changing the from address, it achieves a similar goal, is easy to use, and has a good community. Also, it works perfectly with Google Mail.
I can send an e-mail using php mail function. Other languages also have similar functions.
mail(to,subject,message,headers,parameters)
I was under an impression that to send an e-mail you need SMTP credentials. How does this function send emails? Which SMTP server does it use? How does it work?
In php.ini, there is a field called SMTP. It is where you set the SMTP server. I think it defaults to localhost. Other related fields include smtp_port and sendmail_from. You use these for a Win32 system.
you have to configure your server to send emails ..
You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP.
So if you are using XAMPP then you can easily send mail from localhost.
for example you can configure C:\xampp\php\php.ini and c:\xampp\sendmail\sendmail.ini for gmail to send mail.
in C:\xampp\php\php.ini find extension=php_openssl.dll and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost.
in php.ini file find [mail function] and change
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id#gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Now Open C:\xampp\sendmail\sendmail.ini. Replace all the existing code in sendmail.ini with following code
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id#gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id#gmail.com
Now you have done!! create php file with mail function and send mail from localhost.
PS: don't forgot to replace my-gmail-id and my-gmail-password in above code.
Also, don't forget to remove duplicate keys if you copied settings from above. For example comment following line if there is another sendmail_path : sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe" in the php.ini file
REF : LINK
The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server.
Using the mail() function can be a lot of work. Instead use an external library which greatly simplifies this work for you. One such example is PHPMailer
I upgraded Windows XAMPP to 1.8.3 and am trying to get php working (again) on localhost with Apache 2.4.4, Mercury Mail 4.6, and Thunderbird client 24.1.1. Thunderbird can send and receive mail between two accounts. php's mail() is returning true but no mail is coming through.
php.ini is set to listen on port 25.
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost (I've also tried 127.0.0.1)
smtp_port = 25
Any ideas what I might be missing? Thanks in advance.
Note: sendmail.ini also has
smtp_server=localhost
smtp_port=25
I commented out the following line and it worked.
; sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
For good measure, I changed this to:
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
I don't know why mailtodisk.exe is defaulted to being used, but it appears this simply writes the mail to a folder and it doesn't get delivered.
This my problem,
I have a simple PHP script to send email to localhost with mercury mail server and read it with Mozilla Thunderbird. And it's work.
And then, I upgarde XAMPP version to 1.8.1 and my function return true but no email delivered.
<?php
$to = "root#localhost.com";
$subject = "Hi!";
$body="test";
$headers = "From: root#localhost.com";
if (mail($to, $subject, $body, $headers)) {
echo "Message successfully sent!";
} else {
echo "Message delivery failed...";
}
?>
I tried to send email with Thunderbird to root#localhost.com and it work.
So iI try to change mail function in php.ini to this but not work
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = root#localhost.com
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\php\logs\php_mail.log"
I try to change sendmail.ini to this but not work
; configuration for fake sendmail
; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.
smtp_server=localhost
; smtp port (normally 25)
smtp_port=25
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=auto
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify
;default_domain=mydomain.com
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=
auth_password=
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required.
pop3_server=
pop3_username=
pop3_password=
; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content
force_sender=
; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify
; the "To: " header of the message content
force_recipient=
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
hostname=
Any idea?
If mail returns true, then php's job is done. it's handed the email over to your outgoing mail server. You need to check that server's logs to see what happens from that point forward.
e.g. PHP's role in sending an email is basically the equivalent of taking an envelope you hand it, walking down to the street corner, and dropping it into the mailbox. After that, PHP's done and it can report success.
If that mailbox gets nailed by a drunk driver and the mail gets destroyed, that's not PHP's fault. If the mail gets picked up and sent to a postal sorting facility and then gets lost, that's also not PHP's problem.
So go check your mail server's logs. If it can't deliver the mail, it'll report why. If it DID deliver the mail to the destination server, it'll report so, and then you need to find out why the receiving server isn't doing its job - maybe your email is getting flagged as spam and dump in the trash.
Check this directory: C:\xampp\apache\mailoutput
I recently experienced this problem and after many frustrating hours figured out what was causing it, and how to fix it. Hopefully I can save someone else all that trouble.
My php mail() function was returning true, but I wasn't receiving the messages. In my case, it turned out to have nothing to do with PHP after all.
I use Plesk to manage the sites on my server. This particular version of Plesk doesn't allow me to turn mail services on or off for a given website/domain. I host my email elsewhere.
So here's what was happening: PHP mail() was sending messages, the way it was supposed to. But my server was under the impression that it was supposed to receive messages for the particular domain those messages were addressed to. But there was no such mailbox for that domain, because again I host my email elsewhere.
So the messages were never leaving my server.
The solution was for me to go into var/qmail/control and remove the domain names from the "virtualdomains" file, then restart qmail.
Again, I hope this can save someone else all the time and frustration.
Gregg
Case Solved
I downgrade XAMPP version to 1.7 and it works :)
I had a similar problem. In my case was that I modified the "From" field in the headers. In your example you have
$headers = "From: root#localhost.com";
Maybe this is the problem. See this answer for more information
I tried to send mail in localhost.
but working.
i change the php.ini
[mail function]
SMTP=SMTP.gmail.com
smtp_port =587
sendmail_from =postmaster#testmail.com
sendmail_path = "C: \xampp\sendmail.exe\" -t"
this my php mail function
public function sendMail($to,$subject,$from=null,$headers = null)
{
if($headers == null) {
$headers = $this->setMimes();
}
$headers .= $this->setFrom($from);
return mail($to,$subject,$this->getMessage(),$headers);
}
this mail not sending.
To check/change your PHP mail configuration:
Open your php.ini file (if you don't know where this is, see below) Search for the line that reads [mail function] Add/change the details of your mail server. This could be a local mail server or the mail server of your ISP. Save/close the php.ini file Restart your web server
An example of what the mail settings could look like when you first open the php.ini file:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = me#example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
Additional info is in echoing phpinfo() you can view your PHP configuration details. You can do this by creating a .php file with the following line on it: . When you run this in your browser, you will see a full list of PHP configuration variables. Simply search for the lines that contain php.ini and sendmail_path to see the values you need to use.
Another idea is you might use ini_set() to properly config your mail setting like this
Add the following code to the top of your email script if your mail script continues to fail.
// Please specify your Mail Server - Example: mail.example.com.
ini_set("SMTP","mail.example.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'example#YourDomain.com');