Jump to content

Collect an Email Address then Mail it


maextra7

Recommended Posts

Hey All

Can anyone help me with some code to collect an email address put in by a user on a form, and then when they click submit is auto emails then the info they have requested pulling their email address through from the form?

I am hoping that there could be a field so if people want mor einfo they can put in their email address and click a button to send them the info.

I am a total beginner so please be gentle!  Any help would be greatly appreciated!

Thanks
Link to comment
https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/
Share on other sites

[code]
<?php //php email function
if(isset($_POST['submit'])){
$email = $_POST['email'];
$subject = "More Info";
$from = "[email protected]";// I dont find this perticularly useful, they dont work...
$return = "[email protected]";// This one as well. so dont bother.
$body = "This is where your info goes";

$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: myname<$from>rn";
$headers .= "Return-Path: <$return>";

if (mail($email, $subject, $body, $headers))
{echo "<p><font face=\"Dotum\">Your message has been successfully delivered!</font></p>";}
else
{echo "<p><font face=\"Dotum\">Your message failed to deliver...</font></p>";}?>
<form  name="sendinfo" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input name="email" value="<?php echo"$email"?>" type="text" size="30" maxlength="50" />
<input class="button" name="submit" type="submit" />
</form>[/code]

This is basically it, next time try search in google first  ;)
[code]
<?php

$to = $_POST['email'];
$from = "[email protected]";
$subject = "More Information;
$message="";
$message_html = $_POST['message'];

$boundary = md5(uniqid(time()));


$headers ="From:" . $from . "\n";
$headers .="Return-Path: " . $from .  "\n";
$headers .= "MIME-Version: 1.0" ."\n";


$headers .="Content-Type: multipart/alternative; boundary=" . $boundary . "\n\n";
$headers .= $message . "\n";
$headers .= "--" . $boundary . "\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1" ."\n";
$headers .= "Content-Transfer-Encoding: 8bit". "\n\n";
$headers .= $message . "\n";
$headers .= "--" . $boundary . "\n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1" ."\n";
$headers .= "Content-Transfer-Encoding: 8bit". "\n\n";
$headers .= $message_html . "\n";
$headers .= "--" . $boundary . "--\n";

 
if(mail($to,$subject, '', $headers)) {
echo" Email sent to " . $to . " successfully.";
}

else {
echo "There was an error sending the email.";
}

?>[/code]
Hey

Thanks very much for the really quick replies! 

Got it working sort of... I cannot get the message body (email body) to show.  When I search in google most of it points to an email script using a specified recipent address which is why I thoguht I would pick someone's brains!

I know I have probably done something really silly, anyone able to point me inthe right direction?

Cheers
Mel!  ???

[code]
<?php

$to = $_POST['email'];

$from = "[email protected]";

  $subject = heal($_POST['name']);
  $subject = "Information Testing ".$subject;

$message="Testing Message";

$message_html = $_POST['message'];

$boundary = md5(uniqid(time()));


$headers ="From:" . $from . "";
$headers .="Return-Path: " . $from .  "n";
$headers .= "MIME-Version: 1.0" ."n";


$headers .="Content-Type: multipart/alternative; boundary=" . $boundary . "nn";
$headers .= $message . "n";
$headers .= "--" . $boundary . "n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1" ."n";
$headers .= "Content-Transfer-Encoding: 8bit". "nn";
$headers .= $message . "n";
$headers .= "--" . $boundary . "n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1" ."n";
$headers .= "Content-Transfer-Encoding: 8bit". "nn";
$headers .= $message_html . "n";
$headers .= "--" . $boundary . "--n";

 
if(mail($to,$subject, '', $headers)) {
echo" Email sent to " . $to . " successfully.";
}

else {
echo "There was an error sending the email.";
}

  function heal($str) {
$injections = array('/(\n+)/i',
'/(\r+)/i',
'/(\t+)/i',
'/(%0A+)/i',
'/(%0D+)/i',
'/(%08+)/i',
'/(%09+)/i'
);
$str= preg_replace($injections,'',$str);
return $str;
  }
 

?>


<form  name="sendinfo" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>

<legend id="legend">For more info please enter your email address</legend>
<br />
<input name="email" value="<?php echo"$email"?>" type="text" size="30" maxlength="50" />

<input type="submit" name="submit" value="Submit" id="submit" />
<input class="button" name="reset" type="reset" />

</fieldset>
</form>[/code]

hey, ive got a question, does these:
$headers ="From:" . $from . "";
$headers .="Return-Path: " . $from .  "n";
$headers .= "MIME-Version: 1.0" ."n";


$headers .="Content-Type: multipart/alternative; boundary=" . $boundary . "nn";
$headers .= $message . "n";
$headers .= "--" . $boundary . "n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1" ."n";
$headers .= "Content-Transfer-Encoding: 8bit". "nn";
$headers .= $message . "n";
$headers .= "--" . $boundary . "n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1" ."n";
$headers .= "Content-Transfer-Encoding: 8bit". "nn";
$headers .= $message_html . "n";
$headers .= "--" . $boundary . "--n";


these headers work? do you get a message that you have for $from, or is it your hosts email?

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.