Jump to content

Email script does not send email


billy_111

Recommended Posts

Hey,

 

Does anyone know why this email script does not send an email? It does not give me any errors but the email does not send..

 

This is the code:

 

<?php
$message = '';
if(isset($_POST['submit'])){

if(isset($_POST['tick'])){
	$tick = "No";
} else {
	$tick = "Yes";
}

if($_POST['name'] != "" && $_POST['address_1'] != "" && $_POST['postcode'] != "" && $_POST['email'] != "" && $_POST['tel_mobile'] != "" && $_POST['DOB'] != "" && $_POST['dietary'] != ""){

	// Send email to info @ 		
	$msg = "<h3>New Member Registration</h3>
				<table>        
			        <tr>
			        	<td>Name:</td><td>".$_POST['name']."</td></tr>
			        <tr>
			        	<td>Address 1:</td><td>".$_POST['address_1']."</td>
			        </tr>     
			        <tr>
			        	<td>Address 2:</td><td>".$_POST['address_2']."</td>
			        </tr>     
			        <tr>
			        	<td>Postcode:</td><td>".$_POST['postcode']."</td>
			        </tr>     
			        <tr>
			        	<td>Email address:</td><td>".$_POST['email']."</td>
			        </tr>     
			        <tr>
			        	<td>Tel no - home:</td><td>".$_POST['tel_home']."</td>
			        </tr>     
			        <tr>
			        	<td>Tel no - work:</td><td>".$_POST['tel_work']."</td>
			        </tr>     
			        <tr>
			        	<td>Tel no - mobile:</td><td>".$_POST['tel_mobile']."</td>
			        </tr>     
			        <tr>
			        	<td>Date of Birth:</td><td>".$_POST['DOB']."</td>
			        </tr>     
	        		<tr>
	        			<td>Delivery date (if appropriate):</td><td>".$_POST['delivery']."</td></tr>     
				</table>

				<br/>

				<table>        
			        <tr>
			        	<td>Name of other adults:</td><td>Postcode</td>
			        </tr>     
			        <tr>
			        	<td>".$_POST['name_adult_1']."</td><td>".$_POST['adult_postcode_1']."</td>
			        </tr>     
			        <tr>
			        	<td>".$_POST['name_adult_2']."</td><td>".$_POST['adult_postcode_2']."</td></tr>     
				</table>

				<br/>

				<table>
			        <tr>
			        	<td>Name of child:</td><td>Date of Birth</td><td>Boy/Girl</td>
			        </tr>     
			        <tr>
			        	<td>".$_POST['name_child_1']."</td><td>".$_POST['child_dob_1']."</td><td>".$_POST['child_boy_1']."</td></tr>     
			        	<td>".$_POST['name_child_2']."</td><td>".$_POST['child_dob_2']."</td><td>".$_POST['child_boy_2']."</td></tr>     
			        	<td>".$_POST['name_child_3']."</td><td>".$_POST['child_dob_3']."</td><td>".$_POST['child_boy_3']."</td></tr>     
			        	<td>".$_POST['name_child_4']."</td><td>".$_POST['child_dob_4']."</td><td>".$_POST['child_boy_4']."</td></tr>     
			        	<td>".$_POST['name_child_5']."</td><td>".$_POST['child_dob_5']."</td><td>".$_POST['child_boy_5']."</td></tr>     
			        	<td>".$_POST['name_child_6']."</td><td>".$_POST['child_dob_6']."</td><td>".$_POST['child_boy_6']."</td></tr>     
				</table>

				<br/>

				<table>
	        		<tr>
	        			<td>Do any of the persons listed above have specific dietary requirements?</td><td>".$_POST['dietary']."</td>
	        		</tr>     
	       
				 <tr>
		        	<td>How did you hear about Glo Family</td>
		       		<td>".$_POST['hear']."</td>
		        </tr>     
			</table>

			<br/>

			<table>
				<tr>
		        	<td>How did you hear about Glo Family</td>
		       		<td>".$tick."</td>
 		        </tr>
			</table>
				";
		$to = "[email protected]";
		$from = "[email protected]";
		$subject = "New registration Glo Family website";
		$headers  = "From: $from\r\n";
		$headers .= "Content-type: text/html\r\n";

		mail($to, $subject, $msg, $headers);

} else {
	$message = "<div class='error'>Please fill in all required * fields.</div>";  
}
}
?>

 

Am i doing something wrong?

 

Thanks

 

Regards

Billy

Link to comment
https://forums.phpfreaks.com/topic/205085-email-script-does-not-send-email/
Share on other sites

Are your conditions allowing the script to get to the mail() function?

 

Are you on a local server like WAMP?  Is sendmail configured properly?

 

You gotta handle any possible errors so you know where you (and your user) know where the script is at:

 

change:

 

mail($to, $subject, $msg, $headers);

 

to:

 

if ($mail = @mail($to, $subject, $msg, $headers)) {
    echo 'Mail sent!';
}
else {
    echo 'Mail not sent...';
}

 

At least this way we can see if it's the mail() function which would in turn, usually, be an issue with the mail server.

 

Also, check your error logs.

I realised that the email was being sent but not to certain email accounts.

 

This is my new code:

 

$from = "[email protected]";
            $headers = "From: $from";
            $to = "[email protected]";
            
            $subject = "New registration Glo Family website";
                    
            //begin of HTML message
                $message = <<<EOF
            <html>
              <body>
                  <div style='background:#e1e1e1; padding:10px'>
                        <h3>New Member Registration</h3>    
                                        
                        <br>
                        
                        <table>        
                            <tr>
                                <td>Name:</td><td>$_POST[name]</td></tr>
                            <tr>
                                <td>Address 1:</td><td>$_POST[address_1]</td>
                            </tr>     
                            <tr>
                                <td>Address 2:</td><td>$_POST[address_2]</td>
                            </tr>     
                            <tr>
                                <td>Postcode:</td><td>$_POST[postcode]</td>
                            </tr>     
                            <tr>
                                <td>Email address:</td><td>$_POST[email]</td>
                            </tr>     
                            <tr>
                                <td>Tel no - home:</td><td>$_POST[tel_home]</td>
                            </tr>     
                            <tr>
                                <td>Tel no - work:</td><td>$_POST[tel_work]</td>
                            </tr>     
                            <tr>
                                <td>Tel no - mobile:</td><td>$_POST[tel_mobile]</td>
                            </tr>     
                            <tr>
                                <td>Date of Birth:</td><td>$_POST[DOB]</td>
                            </tr>     
                            <tr>
                                <td>Delivery date (if appropriate):</td><td>$_POST[delivery]</td></tr>     
                        </table>
                
                        <br/>
                
                        <table>        
                            <tr>
                                <td>Name of other adults:</td><td>Postcode</td>
                            </tr>     
</table>
                    </div>            
                    <br>
                    
                    <b>glofamily.com</b>
                    
                    <br><br>
                    
                    <i>p.s. please do not reply to this email.</i>
              </body>
            </html>

EOF;
               //end of message
                $headers  = "From: $from\r\n";
                $headers .= "Content-type: text/html\r\n";
                $headers .= "Cc: [email protected]";

            mail($to, $subject, $message, $headers); 

 

Now the email is being sent to the @hotmail.co.uk account, but not to the @freemanholland.com account. The email is being sent but i dont know why i don't receive it on the other account..

 

What could be the cause of this? The @freemanholland.com account is a work email, which i am using for testing purposes, we actually set up webmail for clients through work, the email i will send this to when ig et it working if [email protected]..

 

As the info@account will be on the same server as the @Freemanholland account i think i will have the same problem..

 

How can i resolve this, it's stupid that it sends to one and not the other..

 

Thanks

From reading http://uk3.php.net/manual/en/function.mail.php

 

In the additional_headers description:

Note: If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822. 

 

Just suggestion though... but as it says, it shouldn't be standard.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.