PHP script not sending email

philb

New member
Joined
Oct 25, 2011
Messages
6
I have a php script which should email me when a visitor submits a suggestion via an html form.

It works on other hosting but I can't get it working with goscomb/directadmin.

Any help would be appreciated.

PHP:
$ewho="######@######.co.uk";
$datesent=date("l dS of F Y h:i A");
$ip=$_SERVER['REMOTE_ADDR'];
$subject="DIY Loft Idea";
$suggestion=$_POST['suggestion'];

$mailbody ="This email was sent via the website form" . "\n\n";
$mailbody .="An idea has been submitted:" . "$suggestion" . "\n";
$mailbody .="DATE: " . "$datesent" . "\n";
$mailbody .="IP: " . "$ip" . "\n"; 

$body .=stripslashes($mailbody);

mail($ewho,$subject,$body);
 
Just got this back from support.

If mail() is not working I would suggest you use SMTP with an authed user/password to the mail server. This is a more elegant solution and less likely to be caught by spam traps also.
 
Any help would be appreciated.

How did you define that is not working? Does mail() give you any error? If yes, then what exactly? Or a recipient does not get an email?

Anyway, whatever you choose: mail() or SMTP, it's up to you to create valid headers, your mails will be marked as Spam by most of legal SMTP servers. So read documentation (and RFC) on how to build valid and actual headers, or find and try a ready class (even coming with PEAR) to send emails. If you choose a 3rd party class to send emails, in most cases it would do all necessary work with headers and formating. And even though hostname and PTR records sometimes make great sense.

Note, SPAM is illegal in most countries, so I hope you are on a right side. And I don't really help to do prohibited things.
 
I'm not spamming, I'm trying to send me a notification email to myself when someone submits a 'recipe suggestion' to the site.

It's an ice cream site where I ask for suggestions on flavour.

Visitors submit their favourite flavour and it's goes into the database then is displayed on the site.

To avoid spam I use reCAPTCHA on the html form.

This all works no problem but I'd like to also receive an email to notify me when someone posts something.

The php code I have is

PHP:
<?php
  require_once('recaptchalib.php');
  $privatekey = "#############################";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
	  include('../private/dbconn.php');
	  
    $con = mysql_connect($hostname, $username, $password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("########", $con);


$sql="INSERT INTO favourites (favourite) VALUES

('".mysql_real_escape_string($_POST['suggestion'])."')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
// echo "1 record added";
header( "Location: http://www.#########.co.uk/readersuggestions.php");
mysql_close($con);
}  


$ewho="######@######.co.uk"; 
$datesent=date("l dS of F Y h:i A"); 
$ip=$_SERVER['REMOTE_ADDR']; 
$subject="recipe suggestion"; 
$suggestion=$_POST['suggestion']; 

$mailbody ="This email was sent via the website form" . "\n\n"; 
$mailbody .="An idea has been submitted:" . "$suggestion" . "\n"; 
$mailbody .="DATE: " . "$datesent" . "\n"; 
$mailbody .="IP: " . "$ip" . "\n";  

$body .=stripslashes($mailbody); 

mail($ewho,$subject,$body); 
?>
 
Just to add I have this working fine on another site hosted with another company.
 
As mentioned above:

And even though hostname and PTR records sometimes make great sense.

Try to change your (or admin) email address in $ewho to another one complete different, hosted on gmail.com or yahoo.com, and see what will happen. If you get an email, read all RFC headers in it and see if there any warnings from antispam software or anything else. Maybe IP of your new hosting is blacklisted or banned at your mail service.
 
That's worked,

I changed the $who to a yahoo.com email and it came straight through.

Shall I assume the hosting is on a banned list, and if so, what do I do now?

Does this mean I need to set up SMTP?
 
Shall I assume the hosting is on a banned list, and if so, what do I do now?

No, ask your hosting company to check mail logs (/var/log/exim/mainlog id Directadmin with Exim is used there).

Does this mean I need to set up SMTP?

Try if you want and see.
 
Back
Top