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.
Related
I have set up a LAMP server with sendmail on Ubuntu 14.04.
When sending mail, either from terminal or PHP mail(), it won't work properly.
When I use mail("user#localhost","test","test"); it sends it correctly, and I can read the message with mail from terminal, but when sending to Gmail address, message won't go trough.
Same outcome when using "test" | mail -s "test" xyz#gmail.com" from server terminal.
Any idea how to fix this?
I have been Googling for several hours now, I have tried everything without finding working solution, and I'm starting to lose hope.
If you're running Ubuntu here is a much simpler solution:
issue from command line >
apt-get install ssmtp
Then edit the configuration file in /etc/ssmtp/ssmtp.conf
A sample configuration to use your gmail for sending e-mails:
# root is the person who gets all mail for userids < 1000
root=your#email.com
# Here is the gmail configuration (or change it to your private smtp server)
mailhub=smtp.gmail.com:587 (leave this the way it is)
AuthUser=your#gmail.com (just change this)
AuthPass=yourGmailPass (and change the password for your gmail account)
UseTLS=YES (leave this the way it is)
UseSTARTTLS=YES (leave this the way it is)
Note: Make sure the "mail" command is present in your system. mailutils package should provide this one in Debian based systems.
Then try send emails again, send it to another domain #gmail, #aol, #yahoo, #privatedomain besides localhost email addresses.
There're tons of possible problems, so you need to get some logs of error that happening.
Most probably, Google just rejects your email as your server is not correctly configured.
I'm attempting to send some test mail to myself while working on a PHP script. I've researched some other questions and it led me to this tool:
http://www.toolheap.com/test-mail-server-tool/
Others have said that it works perfectly but I'm having trouble using it myself. My php.ini files should be reset to default values as I tried to change the SMTP values at one point, but now they are back to "smtp.wlink.com.np".
For anyone that has used this tool, how does it work? Where do I have to send the e-mail to?
$to = "localhost";
?
Set the php.ini SMTP settings to 127.0.0.1 and port 25.
Send the email to anyone, any address (i.e., send it to obama#whitehouse.gov).
The tool will "intercept" the email, and show it to you. The email will never leave your system.
Currently I have a mail server configured (a real one from my ISP) and mail internal and external works on the command line. In PHP only external users work.
For testing I would like to send to internal users only.
( Ideally I would like to set up lots of aliases that point to one user so mail to:
tom#localhost.com, dick#localhost.com, harry#localhost.com end up in /var/mail/johnsmith )
I'd be greatful if someone could help here. I'm hesitant to edit the postfix config files...
On the command line johnsmith#localhost works but not in PHP. It's using cakePHP and I checked the value of $email-addr just before the send ($this->Email->send();) and the value is johnsmith#localhost. I'm not that familiar with cakePHP yet. The var/log/mail shows nothing, only external email addresses.
(server is Suse linux)
You can use the basic mail php function
http://php.net/manual/en/function.mail.php
Under linux, mail php function relies on sendmail, just check that sendmail is properly installed.
In /etc/postfix/main.cf add localhost.com:
mydestination = $myhostname, localhost.$mydomain,localhost,localhost.com
This allows sending on "localuser#localhost.com" via command line. I loaded up a test php mail form script in a browser and it works, sending mail through to /var/mail/localuser.
At the moment it means I have to check each local users /var/mail file. I'm working on the alias. My first attempt at that failed.
I am a newbie in Web Development an I am currently learning PHP and MySQL. I have read HeadFirst PHP and MySQL, and tried the examples. But The PHP Mail() function doesn't work on my Local Machine. I have tried the script on a web server but nothing happens, the mail isn't sent. Please Help me. I have configured the PHP.INI file to send emails but still the problem persists.
<?php
$to = "me#me.com";
$sub = "hello";
$msg = "Hello, how are you?";
//Mail Function
mail($to,$sub,$msg);
?>
I am using WebMatrix with PHP 5.2 installed. Please help me, I am trying out this one since last 2 hours! I am stuck!
mail() uses 'localhost' to send - it generally assumes it's on Linux.
You will need to aquire a basic SMTP server and run it on windows, OR you may be able to use the SMTP server of your're ISP.
Whichever option, you will need to edit your php.ini, you will find:
[mail function]
; For Win32 only.
;SMTP =
you must set SMTP to the ip/port of a mailserver - again wither run one locally or use your ISP.
EDIT
You could try this approach - I have personally never tried to use GMail for sending: http://www.linuxquestions.org/questions/programming-9/php-pear-mail-packege-support-security-through-ssl-586976/
But The PHP Mail() function doesn't work
Yes it does. The problem is either with how you configured PHP or with the MTA you configured it to use. You'd need to provide details of both for us to understand why mail is not getting sent.
The above answer also is applicable to those who use a simulated local IIS e.g. the WebMatrix on IIS Express users who reside within a corporate network with a SMTP machine available.
To be able to send emails out from within it one needs to edit the PHP.INI file (found typically in \Program Files (x86)\IIS Express\PHP\v5.3) and replace 'localhost' with the SMTP server IP or DNS name.
I'm getting this problem:
PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for chris.mahan#gmail.com in c:\inetpub\wwwroot\mailtest.php on line 12
from this script:
<?php
$to = "chris.mahan#gmail.com";
$subject = "test";
$body = "this is a test";
if (mail($to, $subject, $body)){
echo "mail sent";
}
else {
echo "problem";
}
?>
section from php.ini on the server:
[mail function]
; For Win32 only.
SMTP = server.domain.com; for Win32 only
smtp_port = 25
; For Win32 only.
sendmail_from = support#domain.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
(note that "server" and "domain" refer accurately to the actual server and domain name)
In IIS, SMTP is running. Under "Access" tab, "Relay" button, the Select which computers may relay through this virtual server is set to checkbox "only the list below" and on the list is "127.0.0.1(xxx.xxx.xxx.xxx)" (x's representing actual server IP address).
Server is running Windows Server 2003 Service Pack 2, fully patched as of 5 PM Sept 1st 2008. I assume it is running IIS7 (how to check?).
Any ideas?
In reponse to Espo: This machine is hosted at a datacenter. We do not want to use a gmail account (were doing it, want to move away from that). Windows server 2003 comes with its own SMTP server.
Update: Per Yaakov Ellis' advice, I dropped all relay restrictions and added the server IP to the allowed list (using the reverse DNS button provided) and the thing started working.
Thanks to both Espo and Yaakov for helping me out.
Try removing the IP restrictions for Relaying in the SMTP server, and opening it up to all relays. If it works when this is set, then you know that the problem has to do with the original restrictions. In this case, it may be a DNS issue, or perhaps you had the wrong IP address listed.
You are using the wrong SMTP-server. If you you are only going to send emails to your gmail-account, have a look at my answer here.
If you also need to send email to other accounts, ask you ISP for your SMTP-details.
EDIT: I think it is always better to use the ISP SMTP-server as they (should) have people monitoring the mail-queues, checking for exploits and updating the mail-software. If you business is developing web-applications it is almost always best to stick with what you do, and let other people do their stuff (eg running mailservers).
If you still for some reason want to use you local SMTP server, the first thing would be to rule out the php-part. Try folowing KB153119 and then check you SMTPServer IISlog for errors.
EDIT2:
That KB-article says it is for exchange, but the same commands are used for other SMTP-servers (including IIS) as well, so please try and see if you can send mails using the examples from the article.
#Espo: I'll do that re KB153119. Thanks.
About the mail server: I hear you.
I'll update when I uncover more.
#Espo, the article in question relates to Exchange servers, not IIS7.0 SMTP server.
From the summary: This article describes how to telnet to port 25 on a computer that runs Simple Mail Transfer Protocol (SMTP) services to troubleshoot SMTP communication problems. The information in this article, including error messages, only applies to issues when attempting to resolve SMTP communication issues with Microsoft Exchange-based servers and is not intended for general troubleshooting purposes.
I had the same problem, php 5 on iis6, 2003 server. Php always failed when trying to use mail().
I've managed to get it accepting mail from php by changing the Relay Restrictions from 'Only the list below' (which is empty by default) to 'All except the list below' .
The relay restrictions can be found in the Access tab in the smtp servers properties screens.
Of course if the server is open to the internet then one would have to be more sensible about these relaying restrictions but in my case this is on a virtual server on a dev box.
hope that helps.