Where do I put my email address?
#1
Posted 30 January 2013 - 11:47 AM
<?php
$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";
if($_POST['name']!='nope'){
$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}else{
$headers = '';
}
if($_POST['state']!='nope'){
$messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['fax']!='nope'){
$messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
try{
if(!mail($owner_email, $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
?>
#2
Posted 30 January 2013 - 11:49 AM
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#3
Posted 30 January 2013 - 11:50 AM
#4
Posted 30 January 2013 - 11:51 AM
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#5
Posted 30 January 2013 - 11:52 AM
#6
Posted 30 January 2013 - 11:56 AM
<form action="send_form.php" id="ContactForm">
<div class="success"> Contact form submitted! I will be in touch soon.</div>
<fieldset class="left">
<div class="block">
<label class="name">
<span class="title1">Name:</span>
<span class="bg"><input type="text" value="" class="input"></span>
<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>
<label class="email">
<span class="title1">Email:</span>
<span class="bg"><input type="email" value="" class="input"></span>
<span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span></label>
<label class="phone">
<span class="title1">Phone:</span>
<span class="bg"><input type="tel" value="" class="input"></span>
<span class="error">*This is not a valid number.</span> <span class="empty">*This field is required.</span> </label>
</div>
<div class="block">
<label class="message">
<span class="title1">Message:</span>
<span class="bg"><textarea rows="1" cols="2"></textarea></span>
<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
</div>
<div class="formButtons">
<div class="formBtn">
<a href="#" data-type="submit" class="moreButton">Send</a>
</div>
<div class="formBtn">
<a href="#" data-type="reset" class="moreButton">Clear</a>
</div>
</div>
</fieldset>
</form>
#7
Posted 30 January 2013 - 12:08 PM
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#8
Posted 30 January 2013 - 12:13 PM
<?php
$owner_email = $_POST["sebbieharrisonevans@gmail.com"];
$headers = 'From:' . $_POST["email"];
$subject = 'A message from your site visitor ' . $_POST["name"];
$messageBody = "";
if($_POST['name']!='nope'){
$messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
$messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}else{
$headers = '';
}
if($_POST['state']!='nope'){
$messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){
$messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['fax']!='nope'){
$messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
try{
if(!mail($owner_email, $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
?>
#9
Posted 30 January 2013 - 12:15 PM
$_POST is an array. When you do $_POST['field_name'] you are looking for the value of the $_POST array at the field_name key.
$owner_email = $_POST["sebbieharrisonevans@gmail.com"]; is looking for a posted field with the name of your email address.
If you had error reporting on and set to show notices, you'd see this is wrong.
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#10
Posted 30 January 2013 - 12:18 PM
#11
Posted 30 January 2013 - 12:20 PM
Are you trying to learn PHP, or just change the form and then not learn more PHP?
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
#12
Posted 30 January 2013 - 12:21 PM
#13
Posted 30 January 2013 - 12:45 PM
It will help others to read your code easily
Edited by thara, 30 January 2013 - 12:49 PM.
#14
Posted 30 January 2013 - 02:02 PM
How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq
Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












