Jump to content

Where do I put my email address?


SebbieHE

Recommended Posts

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";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/273831-where-do-i-put-my-email-address/
Share on other sites

The form code is below.

 

 

 

 

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

The actual latest code:

 

 

<?php

$owner_email = $_POST["[email protected]"];

$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";

}

?>

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["[email protected]"]; 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.