3

So I've got a script which sends email, it works on one domain on my VPS but not on another which is very confusing! I've checked all the smtp details...etc. and can't see any reason for it. The script runs as though it is successful and throws up no errors and the variables are all in place.

If anyone has any ideas would be hugely appreciated!

<?php
$email=$_POST['email'];
$name=$_POST['name'];
$business=$_POST['business'];
$town=$_POST['town'];
$phone=$_POST['phone'];
$rpo=str_replace("rpo", "RPO",$_POST['rpo']);
$retained=str_replace("retained", "Retained",$_POST['retained']);
$ats=str_replace("ats", "ATS",$_POST['ats']);

$interest=$rpo . ' ' . $retained . ' ' . $ats;
$interest=str_replace('','<br>',$interest);

$msg = "You've received a new enquiry from $name at $business<br>
They are based in $town and interested in:<br>
$interest<br>
You can contact them on:<br>
<b>Phone: </b>$phone<br>
<b>Email: </b>$email<br>
This is an automatically generated email from the company website generated from http://example.com";

$msg = wordwrap($msg,70);

mail('[email protected]','New Enquiry',$msg);

header("location:http://example.com");
?>
8
  • php.net/manual/en/function.mail.php#121163 ? Commented Oct 14, 2017 at 9:41
  • try with if(mail('[email protected]','New Enquiry',$msg)) to make sure the mail function working Commented Oct 14, 2017 at 9:42
  • Done that and it comes up with a blank page i.e. no errors Commented Oct 14, 2017 at 9:43
  • I mean by if(mail('[email protected]','New Enquiry',$msg)){echo "sent";}else{ echo "failed"; } Commented Oct 14, 2017 at 9:44
  • Sorry I was responding to first comment and din't see yours! I'll try that now Commented Oct 14, 2017 at 9:44

1 Answer 1

6

Try this to find out where is the problem

$success = mail('[email protected]','New Enquiry',$msg);
if (!$success) {
   print_r(error_get_last()['message']);
}

with a glance at Php Mail Documentation

Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini. Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

Return Values

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

update After comments just for test, remove every code in your php file an just try the simplest way to debug

<?php
// the message
$msg = "First line of text\nSecond line of text";

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
if(!mail("[email protected]","My subject",$msg)){
    var_dump(error_get_last()['message']);
}
?>
Sign up to request clarification or add additional context in comments.

9 Comments

Thank you, I have done this and it comes up with no error messages at all and everything acts as though it is sent
Hmm what's even stranger is I don't get TRUE or FALSE it is just blank
Ah that's why it says $success is undefined
@Rockhopper have you check it with $success !==true?. yes seems strange.
@Rockhopper check my code again.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.