2

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('example@example.com','New Enquiry',$msg);

header("location:http://example.com");
?>
James
  • 190
  • 2
  • 4
  • 13

1 Answers1

5

Try this to find out where is the problem

$success = mail('example@example.com','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("someone@example.com","My subject",$msg)){
    var_dump(error_get_last()['message']);
}
?>
Yuseferi
  • 7,931
  • 11
  • 67
  • 103