Question

Venerable masters of all things code, I am a simple graphic (not even web) designer, struggling to creating a working mailing script.

So far, I managed to do it with basic HTML and a mailto function, but it needs to happen server-side, so, I am guessing PHP is my best bet.

Here's what I have so far:

<form action="mailto:?subject=Hello" method="POST" enctype="text/plain">
<input type="checkbox" name="Entry1" value="URL1">
<input type="checkbox" name="Entry2" value="URL2">
<input type="checkbox" name="Entry3" value="URL3">
<input type="checkbox" name="Entry4" value="URL4">
<label for="name">Name</label><input type="text" id="name" name="name" placeholder="Your Name">
<label for="email">Email(Required)</label><input type="text" id="email" name="email" placeholder="john_doe@example.com" required class="inputfield">
<input type="submit" id="search-submit" value="">
</form>

What I am trying to accomplish:

  1. An email to be sent from abc@email.com "email" field and a CC to 321@email.com
  2. With a message and Values (URL1,URL2...) from checked Boxes (Entry1,Entry2...)
  3. If successful, redirect to a thank you page.
Was it helpful?

Solution

<?php
if(isset($_POST['send'])){

 $_POST['email'];
 $_POST['name'];
 @$_POST['Entry1'];
 @$_POST['Entry2'];
 @$_POST['Entry3'];
@$_POST['Entry4'];

$to      =  $_POST['email'];
$subject = 'the subject';
$message = $_POST['name'] . @$_POST['Entry1'] . @$_POST['Entry2'] .   @$_POST['Entry3']    . @$_POST['Entry4'];
$headers = 'From:you@example.com';

mail($to, $subject, $message, $headers);
echo 'thanks you for your email';
header("where_you_want.php");
}else{
echo 'please try again';
}

?>

<form action="where_you_want.php" method="POST" enctype="text">
<input type="checkbox" name="Entry1" value="URL1">
<input type="checkbox" name="Entry2" value="URL2">
<input type="checkbox" name="Entry3" value="URL3">
<input type="checkbox" name="Entry4" value="URL4">
<label for="name">Name</label><input type="text" id="name" name="name"     placeholder="Your Name">
<label for="email">Email(Required)</label><input type="text" id="email" name="email" placeholder="john_doe@example.com" required class="inputfield">
<input type="submit" name="send" value="">

this is not the best answer but I test it and sending email with value and you can     change value and play around..I hope its help..

OTHER TIPS

action="mailto:?subject=Hello"

This is not what you think it is.

action specifies the destination URL. mailto: links are sent to the client, the server doesn't do anything with them.

Ex:

"mailto:mr.smith@matrix.com"
"http://www.domain.com"

mailto is like http here.


To send mail using PHP you can the mail function or some other implementation. The action in your form will have to point to a script on your server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top