Dean OBrien
asked on
Sending an Email using PHP
Experts
Im trying to send an email using the code below, it appears to work (i.e. the $success variable is returned a true value, and the email sent message is displayed), however nothing seems to be coming through to my email box...
Any suggestions would be greatly appeciated
Regards
Easynow
Im trying to send an email using the code below, it appears to work (i.e. the $success variable is returned a true value, and the email sent message is displayed), however nothing seems to be coming through to my email box...
Any suggestions would be greatly appeciated
Regards
Easynow
<?php
// email settings */
$CustomerName = trim(($_POST['CustomerName']));
$CustomerEmail = trim(($_POST['CustomerEmail']));
$Telephone = trim(($_POST['Telephone']));
$Postcode = trim(($_POST['Postcode']));
$Enquiry = trim(($_POST['Enquiry']));
$EmailTo = "dean.obrien@unn.ac.uk";
$Subject = "Web enquiry";
// validation
$sendit = true;
if ($CustomerEmail=="") $sendit=false;
if ($Telephone=="") $sendit=false;
if (!$sendit) {
echo 'You forgot to fill out some required fields.';
exit;
}
// prepare email body text
$Body = "Name:" . $CustomerName;
$Body = $Body . "<br>Email:" . $CustomerEmail;
$Body = $Body . "<br>Telephone:" . $Telephone;
$Body = $Body . "<br>Postcode:" . $Postcode;
$Body = $Body . "<br>Enquiry:" . $Enquiry;
// send email
$headers = "From: $EmailFrom";
$success = mail($EmailTo,$Subject,$Body,$headers);
?>
----- HTML --------
<?
// redirect to success page
if ($success){
echo "<p>Your query has been sent.</p>";
echo $Body;
}
else{
echo "<p>There was an error sending your request, please try again.</p>";
}
?>
--- HTML-----
Are you sure that your server is able to send emails?
Try this script to see if your able
<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
Hello,
I have successfully sen the mail with your code. I think your php mail is not enabled.
If you have installed smtp in your system use it
Regards.
I have successfully sen the mail with your code. I think your php mail is not enabled.
If you have installed smtp in your system use it
Regards.
ASKER
Thanks for your comments.
QualitySoftwareDevelopment : the test you propose will give the same result as mine, because they both consider the mail successfully sent if the the function mail() returns true [which was happening with my script].
shobinsun: thanks for testing the script, this confirms that it must be server side.
Just so that i am clear, when i speak to the hosting company, i need to ask them to ensure SMTP is correctly configured for my domain (for my script to work)? or is there any other configurations that i need to check?
Thanks again for all your help.
Regards
Easynow
QualitySoftwareDevelopment
shobinsun: thanks for testing the script, this confirms that it must be server side.
Just so that i am clear, when i speak to the hosting company, i need to ask them to ensure SMTP is correctly configured for my domain (for my script to work)? or is there any other configurations that i need to check?
Thanks again for all your help.
Regards
Easynow
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Google for PHPMailer, that will help you with your problem.
ASKER
Sorry for the delayed response, the problem was as you suggest i hadnt specified the final parameter, and it needed to be from a mail address that the hosting company recognised as there own.
Regards
Easynow
Regards
Easynow