Receiving mail in apache php - php

i have sendmail set up on Ubuntu 12.10, Apache 2.2 and I can now successfully send emails from my local server using php mail() function. I just wanted to know how do i send mail to my server from gmail or perhaps just send mail to my local server from my local server...
I have tried finding my IP addess and sending a mail from my gmail account to somefakeid#myip and i dont seem to see any mail in /var/mail directory..
and by the way just confirming, any recieved mail will be stored in from of a text file in /var/mail whose name will be the username to which the mail was sent right?
i dont see any file named somefakeid...
Please help...
(Isn't there any PHP inbuilt function which checks for any received mail?)

You can use phpmailer class to connect to a remote or gmail server and than send email.
refer to the following link for more information: http://phpmailer.worxware.com/?pg=examplebgmail

You need couple of things, you need a domain and a mx record. when you have the domain you point your mx record to point to your IP and make sure port 25 is open to receive email.

Related

Using Test Mail Server Tool with WAMP?

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.

PHP mail() fails to send mail to same domain name as server [duplicate]

I have a simple php script on my domain that sends me an email:
...
$toMail = "me#gmail.com"; //this works - I get the email at my gmail
$toMail = "me#mydomain.com"; //this doesn't - I get nothing
mail($toMail, $subject, $message, $header);
What setting to I change to fix this?
For the people using Google Apps for email, but having your host in other provider this are more detailed instructions for the people that is not very familiar with cPanel.
I could fix the problem of sending email from my domain using a PHP form, when sending the email to an account inside my domain.
i.e. mydomain.example Contact form sending email to contact#mydomain.example.
The above was not working even if my domain has the correct MX records for the domain using Google Apps.
As Mike noted (and others) above the problem was solved: Adding the MX records into the cPanel.
Enter into the cPanel
Go the the cPanel Mail section
Search for MX Entry Maintenance, sometimes there is no text above the icon.
Select the related domain
Change Email Routing to Remote Mail Exchanger.
Add all the Google MX records as they are in your domain configuration using the appropriate priority values.
You can check the records here and priorities
https://support.google.com/a/answer/174125
Double check that Remote Mail Exchanger. is selected.
With this setting I was able to send email using mail PHP function to an email account inside the same domain as my website.
Google App instructions talking about MX records
https://support.google.com/a/answer/54717?hl=en
I've had this problem myself, when I was redesigning a site recently.
There was an issue with the way our system was set up, so that the system thought that because the email was coming from the same domain it was a spam email and as such blocked it.
Check with your system administrator that you are allowed to be sending the emails etc.
Either that, or you'll have to modify the headers to have look like it's being sent from an external address. Hope you get it sorted.
If you use postfix, do this :
connect to your server via ssh.
edit your main.cf file :
nano /etc/postfix/main.cf
comment the following line with # :
# mydestination = ...
add at the end of the main.cf document :
mydestination =
reload your postfix configuration by running :
/etc/init.d/postfix reload
The top answer at https://serverfault.com/questions/65365/disable-local-delivery-in-sendmail seems correct to me. The gist of it is that you want the following in your sendmail.mc:
define(`MAIL_HUB`, 'example.com.')dnl
define(`LOCAL_RELAY`, 'example.com.')dnl
Where example.com is the domain in question.
You need to set an additional parameter on your mail function. On your working example you would need to prepend your email address with '-f' e.g.
mail($toMail, $subject, $message, $header, "-fme#mydomain.example");
I had the same problem and was able to solve it in the following way. I do not store mail locally on the server but use MX records on the registrar to direct mail into Google Apps. It turned out the MX records needed to be updated in Cpanel as well, as the server was not taking the MX records from the registrar but instead discarding since there was no local MX record or mailbox. I updated the MX entries on Cpanel to match the registrar's MX entries, and the problem was fixed instantly
Do you have your email hosted on a different server than the website? If that is the case the PHP script may be trying to send it internally in which case it'll just disappear, while the other target emails will get put on to the internet and routed properly.
The solution I found was to disable the mail server on your web host, and then PHP will put the message on to the internet to be sent properly.
With PostFix, Debian7, smtp Mailjet
If domain is my-domain.example, in /etc/postfix/main.cf, change
mydestination = my-domain.example, localhost, localhost.localdomain, localhost
to
mydestination = localhost, localhost.localdomain, localhost
I agree with Michael Hellein, the root problem could be your sendmail considering your domain example.com email accounts as local accounts. If so, here are few guiding links:
https://serverfault.com/questions/65365/disable-local-delivery-in-sendmail
https://serverfault.com/questions/102647/sendmail-to-local-domain-ignoring-mx-records-part-2
http://lists.freebsd.org/pipermail/freebsd-questions/2004-September/057382.html
http://objectmix.com/sendmail/367920-sendmail-ignores-mailertable-some-semilocal-domains.html
But in my case, using FreeBSD 8.2, what really did the trick was:
# cd /etc/mail
# vim freebsd.mc
Add these two lines:
define(`MAIL_HUB', `example.com.')dnl
define(`LOCAL_RELAY', `example.com.')dnl
Right before:
MAILER(local)
MAILER(smtp)
Then:
# make
This is output:
cp freebsd.mc host.example.com.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/ /usr/share/sendmail/cf/m4/cf.m4 host.example.com.mc > host.example.com.cf
cp freebsd.submit.mc host.example.com.submit.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/ /usr/share/sendmail/cf/m4/cf.m4 host.example.com.submit.mc > host.example.com.submit.cf
Then:
# cp sendmail.cf sendmail.cf.bak
# cp host.example.com.cf sendmail.cf
# /etc/rc.d/sendmail restart
Hope this saves some headaches to someone.
make sure you can actually send mail to your domain email account and then check your code/email make sure everything is spelled right.. if none of this helped i dont know what went wrong..
I had the same issue, and since I was hosted on another server for e-mail, I just had to disable the local mail server.
I had this problem a few times, and the culprit was if the email was being hosted on another server (e.g. Google Apps). When mail sends to the local domain, it doesn't bother doing a lookup on the MX record and therefore it will not get routed properly. The solution to this problem is just to simply have the mail function disabled on your server by your host.
I had this problem too. Disabling the mail server meant no email at all was sent! So the fix I did was to remove all local domain names from the /etc/mail/local-host-names file
I had a similar issue wherein all mails were being perfectly sent to other domains like gmail, live, yahoo etc but all mails would disappear on local domains.
I had a VPS server with godaddy which was linux based running Qmail.
I solved the problem by removing the specific domain names in var/qmail/control/virtualdomains file .
SMTP mail server could be an option too.
I spend more than 8 hour on this error and solve it just change the header to any other email address and it will work
Make sure your txt record is setup correctly for your domain. This usually happens when you do not put this in the txt record: # (None) v=spf1 include:_spf.google.com ~all
What worked for me is selecting Local Mail Exchanger:
Go to cPanel
Select Email Routing
Select your domain
Select Local Mail Exchanger
Local Mail Exchanger will enable you to send an email to an account of the same domain in GoDaddy: e.g.: an email to info#yourdomain.example
As explained by others, some servers are configured to reject emails missing a valid email address on the sending server. Check that the $headers string includes a defined valid email address From:foo#example.com.

How to get PHP to send mail to local users (cakePHP, Linux SLES)

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.

PHP mail() failing to send to internal addresses

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.

can't send email to addresses at my own domain

I have a simple php script on my domain that sends me an email:
...
$toMail = "me#gmail.com"; //this works - I get the email at my gmail
$toMail = "me#mydomain.com"; //this doesn't - I get nothing
mail($toMail, $subject, $message, $header);
What setting to I change to fix this?
For the people using Google Apps for email, but having your host in other provider this are more detailed instructions for the people that is not very familiar with cPanel.
I could fix the problem of sending email from my domain using a PHP form, when sending the email to an account inside my domain.
i.e. mydomain.example Contact form sending email to contact#mydomain.example.
The above was not working even if my domain has the correct MX records for the domain using Google Apps.
As Mike noted (and others) above the problem was solved: Adding the MX records into the cPanel.
Enter into the cPanel
Go the the cPanel Mail section
Search for MX Entry Maintenance, sometimes there is no text above the icon.
Select the related domain
Change Email Routing to Remote Mail Exchanger.
Add all the Google MX records as they are in your domain configuration using the appropriate priority values.
You can check the records here and priorities
https://support.google.com/a/answer/174125
Double check that Remote Mail Exchanger. is selected.
With this setting I was able to send email using mail PHP function to an email account inside the same domain as my website.
Google App instructions talking about MX records
https://support.google.com/a/answer/54717?hl=en
I've had this problem myself, when I was redesigning a site recently.
There was an issue with the way our system was set up, so that the system thought that because the email was coming from the same domain it was a spam email and as such blocked it.
Check with your system administrator that you are allowed to be sending the emails etc.
Either that, or you'll have to modify the headers to have look like it's being sent from an external address. Hope you get it sorted.
If you use postfix, do this :
connect to your server via ssh.
edit your main.cf file :
nano /etc/postfix/main.cf
comment the following line with # :
# mydestination = ...
add at the end of the main.cf document :
mydestination =
reload your postfix configuration by running :
/etc/init.d/postfix reload
The top answer at https://serverfault.com/questions/65365/disable-local-delivery-in-sendmail seems correct to me. The gist of it is that you want the following in your sendmail.mc:
define(`MAIL_HUB`, 'example.com.')dnl
define(`LOCAL_RELAY`, 'example.com.')dnl
Where example.com is the domain in question.
You need to set an additional parameter on your mail function. On your working example you would need to prepend your email address with '-f' e.g.
mail($toMail, $subject, $message, $header, "-fme#mydomain.example");
I had the same problem and was able to solve it in the following way. I do not store mail locally on the server but use MX records on the registrar to direct mail into Google Apps. It turned out the MX records needed to be updated in Cpanel as well, as the server was not taking the MX records from the registrar but instead discarding since there was no local MX record or mailbox. I updated the MX entries on Cpanel to match the registrar's MX entries, and the problem was fixed instantly
Do you have your email hosted on a different server than the website? If that is the case the PHP script may be trying to send it internally in which case it'll just disappear, while the other target emails will get put on to the internet and routed properly.
The solution I found was to disable the mail server on your web host, and then PHP will put the message on to the internet to be sent properly.
With PostFix, Debian7, smtp Mailjet
If domain is my-domain.example, in /etc/postfix/main.cf, change
mydestination = my-domain.example, localhost, localhost.localdomain, localhost
to
mydestination = localhost, localhost.localdomain, localhost
I agree with Michael Hellein, the root problem could be your sendmail considering your domain example.com email accounts as local accounts. If so, here are few guiding links:
https://serverfault.com/questions/65365/disable-local-delivery-in-sendmail
https://serverfault.com/questions/102647/sendmail-to-local-domain-ignoring-mx-records-part-2
http://lists.freebsd.org/pipermail/freebsd-questions/2004-September/057382.html
http://objectmix.com/sendmail/367920-sendmail-ignores-mailertable-some-semilocal-domains.html
But in my case, using FreeBSD 8.2, what really did the trick was:
# cd /etc/mail
# vim freebsd.mc
Add these two lines:
define(`MAIL_HUB', `example.com.')dnl
define(`LOCAL_RELAY', `example.com.')dnl
Right before:
MAILER(local)
MAILER(smtp)
Then:
# make
This is output:
cp freebsd.mc host.example.com.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/ /usr/share/sendmail/cf/m4/cf.m4 host.example.com.mc > host.example.com.cf
cp freebsd.submit.mc host.example.com.submit.mc
/usr/bin/m4 -D_CF_DIR_=/usr/share/sendmail/cf/ /usr/share/sendmail/cf/m4/cf.m4 host.example.com.submit.mc > host.example.com.submit.cf
Then:
# cp sendmail.cf sendmail.cf.bak
# cp host.example.com.cf sendmail.cf
# /etc/rc.d/sendmail restart
Hope this saves some headaches to someone.
make sure you can actually send mail to your domain email account and then check your code/email make sure everything is spelled right.. if none of this helped i dont know what went wrong..
I had the same issue, and since I was hosted on another server for e-mail, I just had to disable the local mail server.
I had this problem a few times, and the culprit was if the email was being hosted on another server (e.g. Google Apps). When mail sends to the local domain, it doesn't bother doing a lookup on the MX record and therefore it will not get routed properly. The solution to this problem is just to simply have the mail function disabled on your server by your host.
I had this problem too. Disabling the mail server meant no email at all was sent! So the fix I did was to remove all local domain names from the /etc/mail/local-host-names file
I had a similar issue wherein all mails were being perfectly sent to other domains like gmail, live, yahoo etc but all mails would disappear on local domains.
I had a VPS server with godaddy which was linux based running Qmail.
I solved the problem by removing the specific domain names in var/qmail/control/virtualdomains file .
SMTP mail server could be an option too.
I spend more than 8 hour on this error and solve it just change the header to any other email address and it will work
Make sure your txt record is setup correctly for your domain. This usually happens when you do not put this in the txt record: # (None) v=spf1 include:_spf.google.com ~all
What worked for me is selecting Local Mail Exchanger:
Go to cPanel
Select Email Routing
Select your domain
Select Local Mail Exchanger
Local Mail Exchanger will enable you to send an email to an account of the same domain in GoDaddy: e.g.: an email to info#yourdomain.example
As explained by others, some servers are configured to reject emails missing a valid email address on the sending server. Check that the $headers string includes a defined valid email address From:foo#example.com.

Categories