I want to send mails using php from my website. I have done the following steps but still the mail is not working. It is always returning a false.
I have created a mail id and then has changed SMTP, smtp_port and sendmail_from values in php.ini file. I have tested setting the SMTP and smtp to both default values(localhost and 25) and the values given in mail client config of cpanel (abc-22.example.net and 465). I have also checked phpinfo to check whether those values were set successfully. I have checked the error log also, no errors logged there. The php version installed on server is 5.4.24.
Always use SMTP Authentication for mail sending by using phpmailer. mail() is not allowed on some hosting side. Because of spaming.
Click here!
Are you changing the From: attribute in the header?
Some ISPs will block your mail if you do that.
See this SO post
Related
Okay, so I'm new to php, and so I searched this site to find out how to send an e-mail to myself after a user fills out a contact form. I found this answer.
Send email with PHP from html form on submit with the same script
I'm using the code from the selected answer. I tried the top answer, by combining both sections into a single php page, and the second, using an html and php page, but I get the following errors:
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 (MY WEBSITE) on line 14
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 (MY WEBSITE) on line 15
"MY WEBSITE" was put there by me.
Lines 14 and 15 are these:
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2);
Why am I getting this issue? I'm doing exactly what the poster said to do.
You are running PHP on Windows. On Unix-like systems, PHP is able to use the built-in sendmail command to send emails, and so needs no further configuration. On Windows, however, that command doesn't exist, so PHP sends email via an external SMTP server.
In order to send emails, as the error messages explain, you will need to configure your php.ini file or use ini_set() to set the SMTP and smtp_port ini settings. You'll want to specify a SMTP server and smtp_port (usually 25) that you can send email from. If you are running php from your home computer, this would probably be whatever mail server your ISP gave you. If you are are on a third-party hosting provider, you would have to get email server information from them (and they may not actually allow sending email, or may put tight controls on how much you can send, to prevent spam).
The location of the ini file is set by both configuration and convention. PHP's configuration file documentation. On Windows, a long list of registry keys is checked, before eventually falling back to C:\windows or C:\winnt, so that is where you should look for your ini file. (Running php --ini will also show where it's actually trying to read the ini file from.)
There is a sample configuration file shown in the configuration file documentation. If you don't already have a php.ini that was installed when you installed PHP, you can use that format to guide you in creating a new file.
I would bet you are on a Linux server or the host server has the mail function built in turned off. You are not with out options though.
First consider your server. If your server is a shared server and you are likely to have your mail sent to spam if it is delivered at all. Most websites will out source their message systems to keep the load off the server and to ensure delivery.
If you are not in the market for outsourcing your mail services you will need to use a library that will do most of the heavy lifting for you. I would recommend phpMailer it even has an autoset up build in with great examples on how to configure your server.
Next before you install php mailer read your host servers fine print most of them have strict rules about mail (meaning you have to keep a confirmation they wanted the email) if they let you send mail at all. They do this to keep their servers off of spam list.
Good Luck
I have an error while sending e-mail through a php script. Although I changed all the required settings in php.ini like
SMTP "localhost" PHP_INI_ALL
smtp_port "25" PHP_INI_ALL
sendmail_from NULL PHP_INI_ALL
sendmail_path NULL PHP_INI_SYSTEM
I am using wamp. The received error is this:
[function.mail]: Failed to connect to mailserver at "PHP_INI_ALL" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\mail.php on line 10
Why does this error occur ?
WAMP runs on Windows, and windows does not have a Mail Server installed by default.
I would suggest hMailer as I use it myself, but it is not exactly childs play to setup.
Alternatively you could use phpMailer which is a php based utility that will help you send mail using for example a yahoo/gmail etc account.
Wampp doesn't come with a default mail server. You have to install one yourself.
If you only need a mailserver for development purposes you can download the 'smtp4dev' from here: http://smtp4dev.codeplex.com/
From an answer on SO (https://stackoverflow.com/a/7011373/1379394)
t's a beautiful little piece of software that sits in your task bar
and lets you see all email that is being sent to it. It doesn't
actually send email anywhere, so you can work with live data without
fear of spamming someone.
Then, when you want your application to actually send email (when you
run it on the server), you will need an SMTP server address instead of
"localhost". If you don't know which SMTP to use, speak to your
network administrator or ISP.
Hope that will help you.
I'm trying to send an email from my PHP script but it doesn't work. This is the error I get:
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and
"smtp_port" setting in php.ini or use ini_set()
So I've tried to change the port and smtp port by using iniset() function, may i don't know is it possible or not.
If you are on linux you must have a mailserver installed i.e. postfix to do so, issue this command apt-get install postfix and after this the server is started and you can use the php mail() function to send emails!
You'll need to setup a mail server on your localhost. Or, you could connect to an external mail server. Hell, even Gmail allows you to connect via SMTP (cool for testing email scripts etc).
So I've tried to change the port and smtp port by using iniset() function, may i don't know is it possible or not.
It is. See the manual for mail configuration. Both those entries are marked as PHP_INI_ALL
You can prove this by using iniset and then trying your mail call again. The error message will either go away or change (e.g. to complain that it can't connect to whatever server you've said to use instead of localhost:25).
I am trying to using a simple php email
This is working in my production server. But this is not working in my development server. I am not able to find what server configuration is missing
i am getting the error
Unable to send message to SMTP server. No recipients specified. ite. ready. in "filepath" on line 17
What is this ite?
$toemail="me#example.com";
$subject="subject line" ;
$content="conetent message";
$frmemail = "From:you#example.com" ;
mail( $toemail,$subject,$content,$frmemail ) ;
Can anyone suggest what configuration or php ini setting am missing
dev i access on a port .
i saw the exact same error here
http://www.phpfreaks.com/forums/index.php?topic=134654
http://forums.zend.com/viewtopic.php?t=5151&f=77#p23409
but what can be the some security settings blocking sending email from a different domain??
ZMAil
SMTP localhost
smtp_port 25
sendmail_from no value
The fourth parameter - additional headers - is optional. If is not set the sendmail_from option from php.ini will be used.
If you have access to the php.ini file, try to set the option to you#example.com and remove the 4th argument from mail() function.
Changing these settings on the server seems to have allowed the email to be sent successfully. The settings changed were:
AUTOADD(*YES)
ALWRLY(*ALL)
Allow rely mail is the main one
I am trying to send out password reset links for when users forget their password to login to a system I am creating. The problem is, the smtp server is supposedly not configured on the server my system is hosted on. So whenever I try to use the php mail() function to send an email to an internal email address, the emails fail to send, but outside email address (tested with a gmail account), the emails go through. I believe this is because my server is sending directly out to the internet instead of passing through an internal smtp server to resolve where our domain emails should be sent. I was wondering if anyone knew how to configure this on an Xserve or if they knew how to specifically tell the php mail() function where to initially send the email. Any help or pointing in the right direction would be extremely helpful.
Thank you!
mail() doesn't send mail, it just hands things over to the local SMTP server. It does NOT reach out to the recipient's server to deliver the mail. In real world terms, mail() walks your letter down the street and drops it into the neighborhood mailbox. After that, it has absolutely nothing more to do with mail delivery.
Check your local SMTP server's logs to see why the local mails aren't being delivered. There should be a line or two saying why it's registered. Perhaps the local MTA (mail-transfer agent, aka the local "mail man") isn't configured properly.
You can control mail() with it's settings.
This might not solve your overall problem, but hopefully it's useful. This related answer has more information.
We just addressed this problem internally here. Hopefully this will help you as well.
Our environment:
Ubuntu 12.04 LTS
PHP 5.3.10
We could telnet into our SMTP server and send mail from our web server, so it wasn't a permissions issue. When attempting to mail externally, all works perfectly. When attempting to mail internally, silent failure.
Our PHP is using sendmail, which by default, attempts to relay mail to 127.0.0.1. Point this at your SMTP server by editing /etc/mail/sendmail.cf. Update the line from:
# "Smart" relay host (may be null)
DS
to
# "Smart" relay host (may be null)
DSyour.smtp.server.com
Restart sendmail and try sending yourself an email via PHP.
This is something that occurs on Parellels’ PLESK server administration software.
Find your ‘main.cf’ configuration file for PostFix, which for CentOS 6, is located at
/etc/postfix/main.cf
If you can’t find it, do a
which postfix
SSH command to at least see where Postfix is on your server.
Then, open the file up through a text editor, or in the Linux shell, and make these lines (should be at the end of the file, around line 677) :
virtual_mailbox_domains = $virtual_mailbox_maps, hash:/var/spool/postfix/plesk/virtual_domains
virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
virtual_mailbox_maps = hash:/var/spool/postfix/plesk/vmailbox
commented out like this :
#virtual_mailbox_domains = $virtual_mailbox_maps, hash:/var/spool/postfix/plesk/virtual_domains
#virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
#virtual_mailbox_maps = hash:/var/spool/postfix/plesk/vmailbox
Then, restart the Postfix service
sudo service postfix restart
Apache while your at it (can’t hurt), and voila! Your email address should be receiving those emails now. This also doesn’t affect any of your regular emails or anything else, either.