Results 1 to 8 of 8
Thread: PHP cannot send email out
-
11-19-2006, 06:34 PM #1Web Hosting Evangelist
- Join Date
- Sep 2005
- Posts
- 507
PHP cannot send email out
We are using Example 4 from this page to send emails out:
http://www.php.net/manual/en/function.mail.php
Since we moved to our VPS, no emails (tell-a-friend) are going out to Yahoo, Gmail , Hotmail or any emails from domains that are not hosted on the same VPS. Here is the simple test script that can send emails to email addresses whose domains are hosted on our VPS:
<?php
$to .= 'info@mydomain.com; //mydomain.com would be hosted on this same VPS
$subject = 'Birthday Reminders for August';
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
Emails are not arriving unless it is to email addresses on domains that are hosted on the same VPS.
Any ideas?
-
11-20-2006, 01:39 AM #2Web Hosting Master
- Join Date
- Aug 2002
- Location
- Canada
- Posts
- 667
-
11-20-2006, 03:29 AM #3Web Hosting Guru
- Join Date
- May 2006
- Posts
- 279
Also you are missing a from filed so you're sending it from the root. Depending where you send it it might be taken for spam and not delivered.
-
11-20-2006, 06:21 AM #4Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
Why don't you try using phpMailer class? Works 100% properly and very easy to use.
:: www.AsuraHosting.com ::
-
11-21-2006, 02:30 PM #5New Member
- Join Date
- Nov 2006
- Posts
- 1
Could be a DNS issue.
Which MTA are you using.
Try the command
mail -v your-email@gmail.com
from a shell on the server.
-
11-22-2006, 10:41 AM #6Web Hosting Evangelist
- Join Date
- Sep 2005
- Posts
- 507
Thanks for all the replies. It tunred out that Under WHM>>Tweak settings>>Mail, we had to uncheck "Prevent the user "nobody" from sending out mail to remote addresses (PHP and CGI scripts generally run as nobody if you are not using PHPSuexec and Suexec respectively.)" to fix the issue. Unchecked it and things work but still sturggling to understand PHPSuexec and Suexec.
Did some reading and understand half of the technical stuff. Can anyone shed some light in this matter. We are concenred with a spammer using this script to spam.
By the way, thanks maiahost, I missed the From field when copy pasting. We do have that.
And what is phpMailer class?
-
11-22-2006, 12:16 PM #7Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
That's the reason the limit is there in the first place (the limit that prohibits user "nobody" from sending out emails). This is to prevent some site on the server to just start sending out emails via some compromised script, and end up blacklisting the IP of the server and all other sites hosted on there.
PHPsuexec is a method of executing PHP scripts as a user other than the Apache user (normally 'nobody' or 'www' or 'apache' depending on your distribution). This allows scripts to have escalated privileges, and at the same time prevent any script from executing commands as the Apache process.
PHPMailer is a PHP class designed to make it easy to send emails via PHP. It provides methods for attaching files, sending multi-part messages, using SMTP with authentication and other features. Very easy to use, and has quite good in-code documentation.
-
11-23-2006, 08:08 PM #8Web Hosting Evangelist
- Join Date
- Aug 2002
- Posts
- 513
you're forgetting a single quote and have a dotconnector before the =.
PHP Code:$to .= 'info@mydomain.com; //mydomain.com would be hosted on this same VPS
PHP Code:$to = 'info@mydomain.com';