Using Test Mail Server Tool with WAMP? - php

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.

Related

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.

Sending email using xampp localhost

Please help me send email using php, I searched trough google and found out that I need to reconfigure/edit my php.ini and change SMTP value and smtp_port,
I dont know what exactly what will I put on those lines.
Thanks for helping!
It would be a lot easier to use a phpmailer script like this, but you can also do it without that by setting: smtp_ssl = ssl and configure the sendmail.ini so that it connects with your #gmail.com account credentials, or it will not be able to connect.

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.

Configure WAMP server to send email

Is there a way that I can configure the WAMP server for PHP to enable the mail() function?
Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. I'm sure someone more experienced may be able to help, or they may perhaps agree with me.
If you just want to test, here is a great tool for testing mail locally, that requires almost no configuration:
http://www.toolheap.com/test-mail-server-tool/
Install Fake Sendmail (download sendmail.zip).
Then configure C:\wamp\sendmail\sendmail.ini:
smtp_server=smtp.gmail.com
smtp_port=465
auth_username=user#gmail.com
auth_password=your_password
The above will work against a Gmail account.
And then configure php.ini:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Now, restart Apache, and that is basically all you need to do.
Using an open source program call Send Mail, you can send via wamp rather easily actually. I'm still setting it up, but here's a great tutorial by jo jordan. Takes less than 2 mins to setup.
Just tried it and it worked like a charm! Once I uncommented the error log and found out that it was stalling on the pop3 authentication, I just removed that and it sent nicely. Best of luck!
You need a SMTP server to send your mail. If you have one available which does not require SMTP authentification (maybe your ISP's?) just edit the 'SMTP' ([mail function]) setting in your php.ini file.
If this is no option because your SMTP server requires authentification you won't be able to use the internal mail() function and have to use some 3rd party class which supports smtp auth. e.g. http://pear.php.net/package/Mail/
I tried Test Mail Server Tool and while it worked great, you still need to open the email on some client.
I found Papercut:
https://github.com/ChangemakerStudios/Papercut-SMTP
(updated URL for 2021)
For configuration it's easy as Test Mail Server Tool (pratically zero-conf), and it also serves as an email client, with views for the Message (great for HTML emails), Headers, Body (to inspect the HTML) and Raw (full unparsed email).
It also has a Sections view, to split up the different media types found in the email.
It has a super clean and friendly UI, a good log viewer and gives you notifications when you receive an email.
I find it perfect, so I just wanted to give my 2c and maybe help someone.
Sendmail wasn't working for me so I used msmtp 1.6.2 w32 and most just followed the instructions at DeveloperSide. Here is a quick rundown of the setup for posterity:
Enabled IMAP access under your Gmail account (the one msmtp is sending emails from)
Enable access for less secure apps. Log into your google account and go here
Edit php.ini, find and change each setting below to reflect the following:
; These are commented out by prefixing a semicolon
;SMTP = localhost
;smtp_port = 25
; Set these paths to where you put your msmtp files.
; I used backslashes in php.ini and it works fine.
; The example in the devside guide uses forwardslashes.
sendmail_path = "C:\wamp64\msmtp\msmtp.exe -d -C C:\wamp64\msmtp\msmtprc.ini -t --read-envelope-from"
mail.log = "C:\wamp64\msmtp\maillog.txt"
Create and edit the file msmtprc.ini in the same directory as your msmtp.exe file as follows, replacing it with your own email and password:
# Default values for all accounts
defaults
tls_certcheck off
# I used forward slashes here and it works.
logfile C:/wamp64/msmtp/msmtplog.txt
account Gmail
host smtp.gmail.com
port 587
auth on
tls on
from ReplaceWithYourEmail#gmail.com
user ReplaceWithYourEmail#gmail.com
password ReplaceWithYourPassword
account default : gmail
I used Mercury/32 and Pegasus Mail to get the mail() functional. It works great too as a mail server if you want an email address ending with your domain name.

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