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
Related
I've a dedicated server for sending emails with different domain and I'm running nginx and php on the ubuntu server. I've configured ssmtp to send emails which is working fine from terminal using echo from terminal. I want to use php mail function to send mails from the server and I'm using ssmtp. How can I do that? I've made changes in php.ini file in php fpm directory as follows:
smtp_port = 25
sendmail_from = noreply#instaclasses.info
sendmail_path = /usr/sbin/ssmtp
mail.add_x_header = On
I need to configure the php mail function so that any mail sent from mail function is sent from default smtp server configured already.
You can use PHPMailer - this very usefull library. In this all working from all external servers (inc. GMail).
I keep getting this error when I try to send an e-mail in PHP:
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\dressoholic\register.php on line 50
my php.ini looks like this:
[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#yoursite.com
I'm using my laptop as a server.. What am I doing wrong? Thanks.
You need to be running a mail server locally.
If this is Unix, enable sendmail
If this is Windows install the Simple Mail Transfer Server (not sure if the name is correct) component of IIs. E.g. for windows 2003 follow this: http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx
For sending mails using php mail function is used.
But mail function requires SMTP server for sending emails.
we need to mention SMTP host and SMTP port in php.ini file.
Upon successful configuration of SMTP server mails will be sent successfully sent through php scripts.
On windows, nearly all AMPP (Apache,MySQL,PHP,PHPmyAdmin) packages don't include a mail server (but nearly all naked linuxes do have!). So, when using PHP under windows, you need to setup a mail server!
Imo the best and most simple tool ist this: http://smtp4dev.codeplex.com/
SMTP4Dev is a simple one-file mail server tool that does collect the mails it send (so it does not really sends mail, it just keeps them for development). Perfect tool.
If you are running your application just on localhost and it is not yet live, I believe it is very difficult to send mail using this.
Once you put your application online, I believe that this problem should be automatically solved. But i think ini_set() helps you to change the values in php.ini during run time.
First of all, you aren't forced to use an SMTP on your localhost, if you change that localhost entry into the DNS name of the MTA from your ISP provider (who will let you relay mail) it will work right away, so no messing about with your own email service. Just try to use your providers SMTP servers, it will work right away.
PHP mail function can send email in 2 scenarios:
a. Try to send email via unix sendmail program
At linux it will exec program "sendmail", put all params to sendmail and that all.
OR
b. Connect to mail server (using smtp protocol and host/port/username/pass from php.ini) and try to send email.
If php unable to connect to email server it will give warning (and you see such workning in your logs)
To solve it, install smtp server on your local machine or use any available server. How to setup / configure smtp you can find on php.net
Change SMTP=localhost to SMTP=smtp.gmail.com
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?
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 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");