Reputation: 516
doing some quick web dev work for a local body modification parlour just in my spare time; I'm trying to setup a Contact Us form, except when I hit submit, it just returns the die(); method. I'm not too sure what I'm doing wrong, because i'm used to programming Java, and I'd just get the error method for that. Haha. My code is as below if anyone is able to help me, the problem area is within the "contact" case.
<html>
<head>
<title>Darklite Tattoo & Piercing</title>
<link href="src/style.css" type="text/css" rel="stylesheet" /></link>
</head>
<body bgcolor="000048" />
<?php include("src/config.php"); ?>
<div align="center" /><img src="src/img/darklite_banner.jpg" /><br />
<div id="main" />
<?php echo("<a href=\"index.php\" />Home</a> · <a href=\"index.php?x=profiles\" />Profiles</a> · <a href=\"index.php?x=services\" />Services</a> · <a href=\"index.php?x=contact\" />Contact Us</a>"); ?>
<hr>
<?php
$x = $_GET['x'];
switch($x) {
case "profiles":
echo("Le profiles.");
break; case "services":
echo("Body piercings and tattoo's.");
break; case "contact":
if ($_POST["email"]<>'') {
$ToEmail = '[email protected]';
$EmailSubject = 'Site contact form ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
Your message was sent
<?php
} else {
?>
<form action="index.php?x=contact" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
<?php
};
break; default:
echo("Welcome to Darklite Tattoo & Piercing!");
break;
}
?>
</div>
</div>
</body>
</html>
Upvotes: 1
Views: 252
Reputation: 8858
are you testing it on the localhost if yes then you have to setup a mail server in your localhost some of the mail servers are sendmail
, postfix
you have to configure one of them to your local system
Upvotes: 1
Reputation: 3123
To send a mail via php
you need an smtp server. You can set it in your php_ini
config file or by invoking ini_set
beofre using mail
function:
ini_set('sendmail_from', '$from');
ini_set('SMTP', '$smtp_server_address');
ini_set('smtp_port', $smtp_port);
mail(...);
Upvotes: 1