PHP contact form spam help

Hello,

I’m currently building a contact form, but I have one problem, all email is sent directly to my hotmail spam folder,
I’ve read an article or 2 about php headers, but since my php knowledge is very little I didnt tackle the problem.

I was also wondering if it is possible to style the sent e-mail?

Here’s the code :slight_smile:

[php] <?php
$name = $_POST[‘name’];
$email = $_POST[‘email’];
$message = $_POST[‘message’];
$from = ‘From: Epic Concepts’;
$to = ‘[email protected]’;
$subject = ‘Hello’;
$human = $_POST[‘human’];

                    $body = "$name\n $email\n \n $message";
                                
					if ($_POST['submit']) {
						if ($name != '' && $email != '') {
							if ($human == '4') {				 
								if (mail ($to, $subject, $body, $from)) { 
								echo '<p class="correct-message">Your message has been sent!</p>';
							} else { 
								echo '<p class="correct-message">Something went wrong, go back and try again!</p>'; 
							} 
						} else if ($_POST['submit'] && $human != '4') {
							echo '<p class="correct-message">You answered the anti-spam question incorrectly!</p>';
						}
						} else {
							echo '<p class="correct-message">You need to fill in all required fields!</p>';
						}
					}
                ?>[/php]

Thanks for in the advance,

Much regards,

Quincy

You do need headers and yes, its possible to style an email. You do it the same way you would a regular webpage, minus the attached css page. Each tag would have its own style attribute instead.

I’m currently really struggeling styling the emails, with various examples on the internet I still cant seem to manage it :(.

Don’t know what i’m doing wrong :frowning:

This is the code thus far;

[php]
$body =
"

.correct-message{font-weight:bold; color:red;}


New Mail $name\n $email\n \n $message



";[/php]

You’re not doing anything with the style though, its not applied to any of the tags. Did you change the header to reflect that its sending html?

Hey there,

I’m a little bit further, now the html doesnt seem to work, maybe there’s something wrong with my script?

[php] <?php
$name = $_POST[‘name’];
$email = $_POST[‘email’];
$message = $_POST[‘message’];
$from = ‘From: [email protected]’;
$to = ‘[email protected]’;
$subject = ‘Contact formulier bericht’;
$human = $_POST[‘human’];

					$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
					$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
					$headers .= "CC: [email protected]\r\n";
					$headers  = 'MIME-Version: 1.0' . "\r\n";
					$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                    $message = '<html>
								<head>
								<style type="text/css">
									body{background: #EDEBEA;}
									#naam{background:#222222;border:4px solid #DDD;width:650px;}
									#mail{background:#222222;border:4px solid #DDD;width:650px;}
									#message{background:#222222;border:4px solid #DDD;width:650px;}
								</style>
								</head>
								<body>
								<div id="naam">'.$name.'</div>
								<div id="mail">'.$email.'</div>
								<div id="message">'.$message.'</div>
								</body>
								</html>';
                                
					if ($_POST['submit']) {
						if ($name != '' && $email != '') {
							if ($human == '4') {				 
								if (mail ($to, $subject, $message, $from)) { 
								echo '<p class="correct-message">Your message has been sent!</p>';
							} else { 
								echo '<p class="correct-message">Something went wrong, go back and try again!</p>'; 
							} 
						} else if ($_POST['submit'] && $human != '4') {
							echo '<p class="correct-message">You answered the anti-spam question incorrectly!</p>';
						}
						} else {
							echo '<p class="correct-message">You need to fill in all required fields!</p>';
						}
					}
                ?>[/php]

The emails i receive look something like this;

body{background: #EDEBEA;} #naam{background:#222222;border:4px solid #DDD;width:650px;} #mail{background:#222222;border:4px solid #DDD;width:650px;} #message{background:#222222;border:4px solid #DDD;width:650px;}
Henk van de Tillaard
[email protected]
Dit is een bericht voor de nieuwe website van epicconcepts.nl

Mvg Henk

I hope you guys can help me :slight_smile:

Thanks for in the advance!

Sponsor our Newsletter | Privacy Policy | Terms of Service