PHP email issue only working within my domain - php

I have a PHP code hosted on godaddy linux shared hosting
My script is sending email to my domain but not external domain.
I can send an email from hotmail to my domain but cannot send email from my domain to hotmail.
My domain is not listed as spam
Here is the PHP code I am using and working when sending to my domain.
headers = "From: webmaster#mydomain.com \n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
mail($email, $subject, $txt, $headers)
So why is it not getting delivered outside my domain?
I am able to send an email using the script but only on my own adress. me#myserver.com. When I receive it the from adress is wrong. Its not the one i have included in the headers

I'm guessing that your not authenticated your emails before sending (using SMTP). This is commonly blocked by mail servers as it cannot verify where the actual email is coming from. Try authenticating your emails using your SMTP credentials through your Godaddy server and see if that fixes it.

From their documentation,
Two non-CGI form mailers are included in Linux shared hosting account
default files: webformmailer.php and gdform.php. They reside in the
root directory of your hosting account. Incorporating either of these
scripts into your website creates a form to capture user information
and email it to a specified address
SPECIFYING AN EMAIL ADDRESS FOR THE PHP FORM MAILER
To use their PHP form-mailer, you must specify an email address where you want the contents of your form sent to.
Form-mailers cannot send from #aol.com, #gmail.com, #hotmail.com,
#msn.com, or #yahoo.com addresses.
To Specify the Email Address for the Form-Mailer
Log in to your GoDaddy account.
Click Web Hosting.
Next to the hosting account you want to use, click Manage.
In the Tools section of the Hosting Control Panel, click the Form
Mail icon.
Under the Forms Email Address section, type the email address you
want to use with your form-mailer.
Click Continue.
Verify that this is the address you want to use with your
form-mailer, and click Update.
For more information, Please read this page
UPDATE::
The best thing to do is check what PEAR extensions GoDaddy have on there hosting, if they have PEAR mail, you can use that. If not, then you should try using authenticated mail sending.
<?php
include('Mail.php');
$recipients = 'joe#example.com';
$headers['From'] = 'richard#example.com';
$headers['To'] = 'joe#example.com';
$headers['Subject'] = 'Test message';
$body = 'Test message';
$params['sendmail_path'] = '/usr/lib/sendmail';
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);
$mail_object->send($recipients, $headers, $body);
?>
Mail::send() – sends a mail

Related

Mail Function not working in php

My mail function is not working. My mail function is as follows:
function sendmail($from,$to,$sub,$msg)
{
$subject=$sub;
$message=$msg;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <'.$from.'>" . "\r\n";
mail($to,$subject,$message,$headers);
}
This works fine in some of my other project but not working in a new project of mine.
It may be mail not working in your server.
Check with a basic mail function and upload it in your root to test mail.
testmail.php
<?php
$msg = "This is test mail";
mail("tester#email.com","My subject",$msg);
?>
If mail not working then try with authenticated mail like phpmailer, sendmail.
PHP inbuilt mail() function wont work in ur localhost or the server WHICH DOES NOT support smtp server. If you are running this project in ur pc locally then this mail function wont work. you need to upload it in server and then try, it will work!
If you are running this project in server and your mail doesn't fire then possibilities are :
1) You are hosted it in Windows server which supports PHP but not smtp.
2) If server is Linux, then server might have disabled outgoing mail. pls contact your server
I suggest you to use PHPMailer [https://github.com/Synchro/PHPMailer] which sends mail through external SMTP server like GMail,Hotmail etc.. give it a try..
I finally solved the issue. The problem was I had given my gmail id as admin id ( i.e, from address) now i changed it to a mail id from the domain name(say, if the domain name is www.abc.com I gave id as noreply#abc.com) and it works.
And now i came to know that giving gmail or other mail ids will work in some cases in some servers but it wont work on all servers. So using mail id in domain name (noreply#abc.com) will solve this issue. Even though gmail ids works in some servers still it will give a error message in the body of mail or it will be a spam mail so it is better to use mail id derived from domain name like noreply#abc.com.
Thank You....

php mail() sendmail, masquerade as any domain?

I'm running a lamp server on which i'm using the php mail() function to send mail from the current domain (using $username#$_SERVER['HTTP_HOST'] as the source address). I'm using many domains on the same server, and I need the email to come from the correct domain.
Right now I'm using masquerade for a single domain:
dnl # Masquerading options
FEATURE(`always_add_domain')dnl
MASQUERADE_AS(`srv.domain.org')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`masquerade_envelope')dnl
This works fine for this domain, but no other.
How can I set the from-field in php to whatever I want? Right now all email are sent from the same domain, no matter what domain i set in php.
EDIT:
All domain names are CNAME records, pointing to one A record, which points to the server. Every email is using that A record domain name.
You could set the from address in the headers, however, beware that a lot of email clients will mark the emails as spam if the from address and the server domain don't match up.
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com'; // other headers
mail($to, $subject, $message, $headers);
As shown in the PHPDocs for mail()
Gave up, installed postfix, configured it to use a smtp relay, and everything works as expected.
5 minutes, "plug'n'play".

PHP mail is not sending from mydomain.com to the google apps email myname#mydomain.com

When i am trying to send a mail from a contact form in my website using the
PHP mail function its not sending from mydomain.com to the google apps email myname#mydomain.com.
Please suggest a solution for the issue.
After a very long research, I found the answer to this problem.
For me, the problem is in my host settings.
You host treats those domain addresses as they were registered with itself not with Google Apps. So it routes the emails to hosts mail server.
To route it through Google Apps (Gmail), you need to change the email routing settings.
Find "MX Entry" settings in your cpanel and add a new MX Record with priority
0
and destination
gmail.com
and add it. You should also change the existing MX Record priority to 1.
These settings will let your receive emails from php mail() to your Google Apps gmail account.
To send email from PHP you must have an SMTP server installed and have PHP configured to use the server. If you are using shared hosting or have it set up, you should check that you are calling the mail function correctly by checking the documentation.
Here is an example of how it is used:
$to = "name#example.com";
$subject = "Test Message";
$message = "Hello!";
$headers = "From: me#example.org";
mail($to, $subject, $message, $headers);
Just modify the /etc/hosts file and add your IP Address mydomain.com mydomain in the next line, this should work by routing emails to google's servers .I did the same for my site.
So my /etc/hosts file looks like this :
127.0.0.1 localhost
IP mysite.com mysite(this is an alias and you can call it anything i suppose)

Mail being sent to gmail, yahoo, but not to personal mail servers

I am facing a weird problem. When I send out mails using PHP's mail() function, the mail is being sent perfectly to gmail and yahoo(though it was marked as spam in yahoo), but the mail is not received by my company's email address.
I don't have direct access to the server, only ftp to the public_html folder, hence I can't check the logs.....
Any ideas or suggestions?
EDIT:
$mailfrom="website#mysite.com";
$mailto=$buyerrow['email'];
$subject="Test Details";
$body='Hi '.$buyerrow['name'].'!<br>Test Details below:<br><br><br><br><br>Thanks<br>Web Team';
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; carset=iso-8859-1;\r\n";
$headers.= "From: ADMIN <".$mailfrom.">\r\n";
#mail($mailto,$subject,$body,$headers,"-f website#mysite.com");
As for the spam folders at my company's server, I am quite sure it didn't end up there either....
Is it possible that there is some server setting which allows php to send mail to only particular server?
Many company mailservers are set up to outright reject some types of spam immediately during the SMTP session. If that happens, it will never make it to your companies spam folder. You should check with your company system administrator.
If you're in doubt, you can always use an application like Wireshark to capture and analyse the actual SMTP traffic.
Have you checked on the Spam folder ? also check whether you have set HEADERS properly with from name etc.,
The problem seems to be with your company's server mail server.
Make sure to test it [send email from yahoo to your company email address] and double check the mx records.

why is php mail script not sending mail

<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("example#gmail.com", "hello", "nothing",$headers);
echo "mail sent";
?>
but it does not actually send the mail please help me out with this
The mail function is just an interface to the local mail server. The mail functionality in PHP relies on the machine PHP is running on to be correctly configured and able to dispatch e-mail. Check the mail system configuration on the machine.
check the following -
check if your smtp server is running (you could either check through command line tools or try ftp'ing to port 25).
If your smtp server is running. Then try to send a mail manually (without script). Use the command-line mail command (I am assuming you have unix here).
Also, when you run your script, what happens? It could be possible that your mail is in a Queue. From your terminal type 'mailq'. This shows the current emails in Queue & why they are there. Also there is a corresponding log to this. You could also check that out for info.
My guess is if all the above are running, you are good to go.
please check following ** Please verify your servers sender domain policy**
Emails sent through your servers (mail servers and shared web servers) should use a from address that is hosted here at your server. Emails that are sent with a from address hosted somewhere else (like Hotmail or Google) may be blocked.
ie use
$header = "From:example#/*yourhostname.domain name*/ \r\n";

Categories