Jump to content


Photo

Where do I put my email address?

php email contact form send

  • Please log in to reply
13 replies to this topic

#1 SebbieHE

SebbieHE

    Member

  • Members
  • PipPip
  • 13 posts

Posted 30 January 2013 - 11:47 AM

Hello. Please could someone tell me where to put MY email address so that when they send the message, I receive the email?


<?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 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 30 January 2013 - 11:49 AM

If you look up mail() in the manual you can see what the arguments are. The first one is the email address to send the mail to.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

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 SebbieHE

SebbieHE

    Member

  • Members
  • PipPip
  • 13 posts

Posted 30 January 2013 - 11:50 AM

See. I put my email address there and the form still didn't work. Any advise?

#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 30 January 2013 - 11:51 AM

Why don't you show us THAT code.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

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 SebbieHE

SebbieHE

    Member

  • Members
  • PipPip
  • 13 posts

Posted 30 January 2013 - 11:52 AM

What do you mean by 'THAT'? The actual form?

#6 SebbieHE

SebbieHE

    Member

  • Members
  • PipPip
  • 13 posts

Posted 30 January 2013 - 11:56 AM

The form code is below.




<form action="send_form.php" id="ContactForm">
<div class="success"> Contact form submitted!&nbsp;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 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 30 January 2013 - 12:08 PM

The code where you put in your email. You should always post your latest code when you want help with it. Code that's two iterations old...wastes our time.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

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 SebbieHE

SebbieHE

    Member

  • Members
  • PipPip
  • 13 posts

Posted 30 January 2013 - 12:13 PM

The actual latest code:


<?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 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 30 January 2013 - 12:15 PM

See, that's a lot more useful. Could have saved 5 or so posts.




$_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.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

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 SebbieHE

SebbieHE

    Member

  • Members
  • PipPip
  • 13 posts

Posted 30 January 2013 - 12:18 PM

I use notepad++. What software would you recommend? Thank you for the help by the way.

#11 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 30 January 2013 - 12:20 PM

Your problem has absolutely nothing to do with your text editor.

Are you trying to learn PHP, or just change the form and then not learn more PHP?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

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 SebbieHE

SebbieHE

    Member

  • Members
  • PipPip
  • 13 posts

Posted 30 January 2013 - 12:21 PM

Trying to learn.

#13 thara

thara

    Advanced Member

  • Members
  • PipPipPip
  • 416 posts
  • LocationPanda

Posted 30 January 2013 - 12:45 PM

when you post your code again please place it inside code tag by clicking on the button '<>' in your editor

It will help others to read your code easily

Edited by thara, 30 January 2013 - 12:49 PM.

IT consultation and Integration : Web Design and Web Development.

#14 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 30 January 2013 - 02:02 PM

You need to put your email address as a string, and assign it to the variable. Go read the PHP manual.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

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

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com