Reputation: 5600
I got the following code and before sending i check the fields are populated or not...when sending the email i get the message 'We have received your email .' but i cannot see the email in my inbox, tried it with two different emails but same results... cannot figure out why can you help me please. here is the code:
if($badinput == NULL){ ?>
<h2>We have received your email .</h2>
</div>
<?php
require_once("libs/inc.email_form.php");
$email_fields = array(
"Name" => $_POST['name'],
"E-Mail Address" => $_POST['email'],
"Telephone Number" => $_POST['telephone'],
"Callback" => $_POST['callback'],
"Enquiry" => $_POST['enquiry']
);
contact_form( "[email protected]", $_POST['email'], " Enquiry", "test", $email_fields);
}
else
{
echo $badinput . "</div>";
}
?>
here is the function in libs/inc.email_form.php:
function contact_form($to, $from, $subject, $message, $fields){
if(!$to || !$from || !$subject || !$message || !$fields){
print form function is missing a variable";
return false;
}
$msg_body = $message."\n\nSubmitted ".date("l, F j, Y, g:i a")." [EST]\n\nSUBMISSION DETAILS:\n";
// clean up all the variables
foreach($fields as $k => $v){
$msg_body .= "\n".$k.": ".clean_var($v);
}
// add additional info
$referer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "could not determine" ;
$user_agent = (isset($_SERVER['HTTP_USER_AGENT'])) ? $_SERVER['HTTP_USER_AGENT'] : "could not determine" ;
$msg_body .= "\n\nAdditional Info:\nIP = ".$_SERVER['REMOTE_ADDR']."Browser Info: ".$user_agent."Referral: ".$referer." \r";
// send it
$emailer = new emailer;
if(is_array($to)){
foreach($to as $t){
$emailer->send_email($from, $subject, $msg_body, $to);
}
}else{
$emailer->send_email($from, $subject, $msg_body, $to);
}
return true;
}
Upvotes: 0
Views: 1097
Reputation: 4916
Is that a 100% accurate representation of your script?
There appears to be a major syntax error, which if it somehow doesn't error out on you, will at least totally change the script's functionality.
if(!$to || !$from || !$subject || !$message || !$fields){
print form function is missing a variable";
Surely, it should be:
if(!$to || !$from || !$subject || !$message || !$fields){
print "form function is missing a variable";
Upvotes: 0
Reputation: 136
It doesn't seem that your actually checking the return value from the $emailer class, so the function telling you your email is sent really is just a false positive.
I would change:
$emailer->send_email($from, $subject, $msg_body, $to);
to:
$result = $emailer->send_email($from, $subject, $msg_body, $to);
print_r($result);
and check what the $emailer class is returning. more then likely it's going to be a "0" for failed or "1" for success.
Upvotes: 1
Reputation: 1840
I see no reason for using a class if it's just probably still using the standard PHP mail() function.
Please try using this code to test if mail actually get sent:
if (mail('[email protected]', 'subject', 'test email'))
echo 'Mail was sent';
else
echo 'Mail could not be sent';
Also please check the Spam folder as many emails send through PHP mail() get flagged as spam due to incorrect or incomplete headers or because of abuse and bad IP reputation (especially if you're using shared hosting).
Upvotes: 2