0

I have a website hosted with hostmonster. I have a simple subscribe form which sends an email to my email account to notify me when someone subscribes. The code is below:

//SEND EMAIL START --------------------------------------------
$to  = '***@***.com';

// subject
$subject = 'Subscriber';

// message
$message = '
<html>
<head>
  <title>Subscriber</title>
</head>
<body>
<p style="font-size:x-large;text-align:center">Subscriber</p>
<p>A person has subscribed to www.***.com.</p>
<p><strong>Name:</strong> ' . $name . '</p>
<p><strong>Email:</strong> ' . $email . '</p>
<p></p>
<p style="font-size:x-small;text-align:center">Email sent from ***@***.com.<br>
</body>
</html>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: NAME <***@***.com>' . "\r\n";
$headers .= 'Reply-To: NAME <***@***.com>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";

$eLog="tmp/mailError.log";

//Get the size of the error log, ensure it exists, create it if it doesn't.
$fh = fopen($eLog, "a+");
fclose($fh);
$originalsize = filesize($eLog); 

@mail($to,$subject,$message,$headers);

clearstatcache();
$finalsize = filesize($eLog);

if ($originalsize != $finalsize) {
print "Problem sending mail. (size was $originalsize, now $finalsize) See $eLog";
} 
//SEND EMAIL END --------------------------------------------

I have copied this file and created another file where you can unsubscribe. Exactly the same code. The unsubscribe file does not send the email to me but the subscribe does.

What have I done wrong? I am confused. There are no errors that I can see. The log file says:

mail() on [/home2/***/public_html/***/subscribe.php:80]: To: ***@***.com -- Headers: MIME-Version: 1.0  Content-type: text/html; charset=iso-8859-1  From: *** <***@***.com>  Reply-To: *** <***@***.com>  X-Mailer: PHP/5.4.43
mail() on [/home2/***/public_html/***/unsubscribe.php:78]: To: ***@***.com -- Headers: MIME-Version: 1.0  Content-type: text/html; charset=iso-8859-1  From: *** <***@***.com>  Reply-To: *** <***@***.com>  X-Mailer: PHP/5.4.43
Munnaz
  • 35
  • 11
  • Hi, I would suggest using something like PHPmailer it super easy to use and has a full set of features. You'll never use regular mail again. Your gonna have issues with this `"\r\n"` Them line endings can be a real **** in mail. http://stackoverflow.com/questions/4415654/which-line-break-in-php-mail-header-r-n-or-n – ArtisticPhoenix Jun 28 '16 at 05:07
  • Also I don't understand your error message `print "Problem sending mail...` the mail is already sent at that point. – ArtisticPhoenix Jun 28 '16 at 05:10
  • Thanks. I will have a look at PHPmailer but I would still like to know what the problem is since they are identical. Its just checking if there is a error log placed in tmp/mailError.log. If there is it will print an error. – Munnaz Jun 28 '16 at 05:59
  • Email, can be really hard to debug. It's sort of fire and forget when it comes to sending it. 2 things you can do, remove the `@` infront of `mail()` this suppresses errors. and do if( !mail( ) )` and output there. All you know right now is that you are not getting the email. Not if it is not sending it. Could be firewall, port issues, email headers ( line endings ) etc. – ArtisticPhoenix Jun 28 '16 at 06:06
  • On the surface I don't see any syntax errors, just looking at it. But email is tough. Once you use PHPMailer, or Rmail. You'll never mess with that stuff by hand. – ArtisticPhoenix Jun 28 '16 at 06:09

1 Answers1

0

Is port 78 being blocked? Or reserved for another program?

brt
  • 154
  • 1
  • 2
  • 12
  • I'm assuming that is the line number of the php file as the mail() command is on line 80 (subscribe) and 78 (unsubscribe) – Munnaz Jun 28 '16 at 05:56
  • 78 would be the port, such as HTTP is port 80 and ftp is port 21 etc. Think of ports like application connections to the internet. The port is how they transfer information like a Chanel. – ArtisticPhoenix Jun 28 '16 at 06:11