I am trying to send mail using PHP Mailer but there is an issue with setfrom() method
In $mail->setFrom('abcd#abcd.com', 'Jay');
When I use domain name .com mail gets sent and received properly
But when I use . co domain name example $mail->setFrom('abcd#abcd.co', 'Jay');
Its doesn't show any error and says mail sent successfully but mail isn't received on my account.Tried changing google privacy settings.
Note:Not using SMPT kept it to false using default settings
Update:Ok so the thing is It is working but the emails are being receive after hours and hours if I use .co but when I use .com email are received immediately.
Probably server problem.
This sounds like a known problem that's been answered before: gmail does not allow setting arbitrary from addresses. You can preconfigure aliases in settings, but you can't simply start using them at the sending client. You can see the submission conversation by setting $mail->SMTPDebug = 2;, but if it's sending successfully, PHPMailer has no involvement beyond that point.
Ok so the problem was the server (bluehost)
What was happening is whenever the setFrom() had an email address whose sub domain was not '.com' eg: " abcd#abcd.co,abcd#abcd.in" the mail was being received after several hours.
It would work normally if setfrom() was set to a normal address eg: a#gmail.com .
Probably a server issue.
Related
My PHP script sending mail to all other mail perfectly, but not getting any mail in trustmedi.com. Ff I send mail from my gmail to dummy#trustmedi.com, it's working. I had already tried gmail smtp, PHPmailer but it's not working. My dummy.trustmedi.com is using gmail server.
from my previous post I have got following answer
The main reason is that your domain is listed on SORBS DUHL black list which says:
Additional Information: [Dynablock] Dynamic IP address, use your ISPs
mail server Listed but has active as exception(s) and therefore might
NOT be blocked.
166.62.27.124 is an active exception for the network 166.62.24.0/22.
166.62.27.151 is an active exception for the network 166.62.24.0/22.
I am using PHP's mail() function, but I am unable to send mails to the majority of servers.
It send mails to the GMAIL without problems...Probably the rest of servers simply deny my mails...I set the MX records of the mail servers that I need...And I changed my PTR record to mail.example.com......however stil cant send mails..How can I solve this problem?
In addition, messages' sender is displayed as "www-data#localhost"
(I am using Digital Ocean, Ubuntu 12.04)
Errors that I am getting in log file:
My unqualified host name (localhost) unknown; sleeping for retry localhost sendmail[11620]: unable to qualify my own domain name (localhost) -- using short name(errors that I get in mail.err); and in log file it shows some errors regarding verification, Do I need to install smt regarding STARTTLS=client
when using the mail() function ypou neet to set the SENDER as well as teh from/to etc.
i.e.
mail($to, $subject, $body, $headers, "-f ".$webmaster);
The important thing is that "-f ".$webmaster that allows you to override the default of 'www-data#localhost' as the BOUNCE address (Envelope sender) for failed mail..
Most mailers will reject e-mail with an invalid bounce address.
Many hosted servers will not let you set the -f value tho...it sets the 'real sender' and of course its a classic way to send spam..
Try with the -f and if it fails change your hosting company.
Or get yourself a virtual private server.
I had the same problem and one thing you can do is: open a ticket with digital ocean support. By default, new accounts have a block to send e-mails (to avoid spammers). They resolved quickly and greatly improved.
Another thing is: check your mail reputation. You can find some websites that can help with this, like mail-tester.com - This site provides a report with potencial issues to fix the problem.
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.
I am piping all e-mails through a PHP script that checks the To address against a database of valid addresses. If it exists, the rest of the script handles it. However, if it does not exist, how can I bounce the e-mail, the same way the server would if I didn't have the script? Thanks!
The mails are recieved through smtp protocol, in your case also i assume that there is some service running on port 25 which would listen to request for mail from external domains.
There are different ways to bounce the message
->bounce at smtp level itself, as in when u get the recipient list, check f
or the id existance and if does-not exists give a 4xx response. The bouncemai
l would then be generated by the senders domain automatically.
-> if you have accepted the mail from the domain say gmail.com then u will
have to make a new connection to gmail with your bouncemessage, this is same
as sending a new mail from your server to gmail.com.
Turns out this was very easy to solve: Simply echo something in the PHP script (for example, "This account does not exist.") and the mailer daemon generates a bounce-back e-mail with this output included.
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.