Jump to content

Email Confirmation Help


just1ncase

Recommended Posts

I'm having trouble with my email confirmation. They inconsistently not being sent to the people who submitted the form. I'm not sure whether I have my PHP code set-up correctly. The following is my PHP Code for my email confirmation:

 

<?php     

$to=""; 
$subject=""; 
$message=""; 
$headers=""; 


/*Payment Email Method*/ 

if ($paymentMethod == "Paypal") { 
        $emailPayment = "Credit Card/Paypal"; 
    } else { 
        $emailPayment = "Check<br/> 
<br/>             
Payment Instructions here. 
<br/>"; 

} 

$to = $email; 
$subject = "Registration Confirmation"; 

$message = '<html> 
<body> 

Content introduction here. <br/><br/> 

Registrant Information<br/> 
----------------------------------------------------------<br/> 
Name: '.$name.'<br/> 
Title: '.$title.'<br/> 
Address: '.$address1.'<br/> 
Address 2: '.$address2.'<br/> 
'.$city.', '.$state.' '.$zip.'<br/> 
Home Phone: '.$phone.'<br/> 
Office Phone: '.$office.'<br/> 
Fax: '.$fax.'<br/> 
Email: '.$email.'<br/> 
<br/> 
<br/> 
Method of Payment<br/> 
----------------------------------------------------------<br/> 
'.$emailPayment.'<br/> 
<br/> 
Registration Type<br/> 
----------------------------------------------------------<br/> 
'.$emailReg.'<br/> 
<br/> 
Credits<br/> 
----------------------------------------------------------<br/> 
'.$emailCredit.'<br/> 
<br/> 
Cost<br/> 
----------------------------------------------------------<br/>   
Initial Conference Fee: $'.$emailCost1.'<br/> 
CE Credit Option Fee: $'.$emailCost2.'<br/> 
-----<br/> 
Grand Total: $'.$totalCost.'<br/> 
</body> 
</html>'; 

$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
      
$headers .= "From: My Website <website@mywebsite.com>\r\n"; 
$headers .= "CC: me@mywebsite.com\r\n"; 


if (mail($to, $subject, $message, $headers)) { 
  echo(" "); 
} else { 
  echo("<p>Message delivery failed.</p>"); 
} 


?>

Is the if and else function for mail set-up correctly? Or should I just remove the else function because it's not needed to echo whether a person's message failed?

 

Please let me know. Any help is appreciated. Thanks!

 

I'm new to this forums and I just love the great functionality of PHP. I hope to help others with my avid PHP knowledge as well. Thanks again!

Link to comment
Share on other sites

The ELSE is fine. Your code seems to be correct (as long as mysite.com is replaced with your actual site in the headers) and should send atleast at the software level.

 

The best chance of your e-mails not sending is either the SMTP server has error authenticating the headers, or is/was not reachable at the time it is sent. Try looking in logs.

Link to comment
Share on other sites

If it is a header problem, here's the header I use on my site. Never had an email missed, that I know of:

 

$from=me@here.com
$headers = 'From: '.$from.'' . "\r\n" .
    'Reply-To: '.$from.'' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

 

 

Link to comment
Share on other sites

Thank you so much for the quick response!

 

Yes, the "My Website <website@mywebsite.com>" will replaced the correct website name and email address. How would I be able to examine the logs?  The odd thing is it was working just fine before, but stopped working all of a sudden now—Not sure why.

 

It may be the error authenticating the headers

Link to comment
Share on other sites

If your server has no SMTP logs then you're most likely using a shared host, if so then records sometimes need to be set or changed for proper use of PHP's mail function from the host itself. I'd recommend pinging your server (port 26 usually) over time and see if it's reachable, such as your MX records, but you really should ask your host to check if everything is alright on the record end.

Link to comment
Share on other sites

I couldn't find the SMTP logs, but I did find the website log (consisting of the web activity based on their IP address). From there, I was able to pin point the issue and resolve it from there. I think it wasn't a SMTP headers issue—instead, it may have been that email php function wasn't actually being accessed at all for it to trigger the email confirmations. So, I made that correction to the webpage.

 

One question though: is it possible to send a copy of the email confirmation to me without my email address being on the CC line?

 

Thanks again!

Link to comment
Share on other sites

Sounds like it could be the recipients spam filter blocking the email. What are you using for the from email address, something like noreply@mysite.com? If so, it helps if that mailbox actually exists because some email providers will treat it as spam if the senders email address is nonexistent.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.