/    Sign up×
Community /Pin to ProfileBookmark

PHP contact form doesnt send email

I am utilizing this contact form and when tested the email is not sent. Does anyone know what may be wrong with my coding?

[CODE]
<?php

$from = “[email protected]”;
$from_name = “My Company”;
$subject = “Contact Form”;

$to = $_POST[‘[email protected]’];

// collect data
$body = “”;
foreach($_POST as $key => $val)
{
if($key != ‘captcha’)
$body .= ucfirst($key).”: “.$val.”rn”;
}

// construct MIME PLAIN Email headers
$header = “MIME-Version: 1.0n”;
$header .= “Content-type: text/plain; charset=utf-8n”;
$header .= “From: $from_name <$from>rnReply-To: $from_name <$from>rnReturn-Path: <$from>rn”;

// send email
$mail_sent = mail($to, $subject, $body, $header);
?>

[/CODE]

[CODE]

<form method=”post” onsubmit=”return sendContact();” action=”sendContact.php”>
<p>
<label for=”name” id=”lname”>Full name:</label>
<input type=”text” class=”text” name=”name” id=”name” onfocus=”input_focus(‘name’);” onblur=”input_blur(‘name’);” />
</p>

<p>
<label for=”email” id=”lemail”>Email address:</label>
<input type=”text” class=”text” name=”email” id=”email” onfocus=”input_focus(’email’);” onblur=”input_blur(’email’);” />
</p>
<div class=”x”></div>
<p class=”error” id=”email-error”>You must enter your email address.</p>

<p>
<label for=”category” id=”lcategory”>Select One:</label>
<select name=”category” id=”category” onfocus=”input_focus(‘category’);” onblur=”input_blur(‘category’);”>
<option value=”resources”>Customer Service</option>
<option value=”software”>Sales Department</option>
<option value=”hardwae”>Technial Department </option>
<option value=”consulting”>Press Department</option>
</select>
</p>

<p>
<label for=”message” id=”lmessage”>Message:</label>
<textarea name=”message” id=”message” onfocus=”input_focus(‘message’);” onblur=”input_blur(‘message’);”></textarea>
</p>
<div class=”x”></div>
<p class=”error” id=”message-error”>You must enter your message.</p>

<p>
<label for=”captcha” id=”lcaptcha”></label>
<input type=”text” class=”text” name=”captcha” id=”captcha” onfocus=”input_focus(‘captcha’);” onblur=”input_blur(‘captcha’);” />
</p>
<div class=”x”></div>
<p class=”error” id=”captcha-error”>Are you sure about your calculations?</p>
<script type=”text/javascript”>
generate_captcha(‘lcaptcha’);
</script>

<div class=”x”></div>

<input type=”submit” class=”submit” name=”send_contact” value=”Send” />

</form>
[/CODE]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@JerailJan 19.2010 — What is this line supposed to mean?[code=php]$to = $_POST['[email protected]'];
[/code]

That implies that on the form there was a field like[code=html]<input name="[email protected]">[/code]

If you want to always send it to the same e-mail, it should be just [code=php]$to = '[email protected]';[/code]

And I would think this:[code=php]$from = "[email protected]";
$from_name = "My Company";
$subject = "Contact Form";
[/code]


Should maybe be this:[code=php]$from = $_POST['email'];
$from_name = $_POST['name'];
$subject = $_POST['category'];[/code]
Copy linkTweet thisAlerts:
@ne_plusauthorJan 19.2010 — Works great! You are awesome! Thank you!
×

Success!

Help @ne_plus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...