PHP - Send Email From Form Input Help
I am stumped here, can not figure out a efficient way to collect all the data on this page and send it to my to user's id number.
I am trying to format the email to include question #1 and then next to it radio1 (answer yes/no) , question#2 and so on followed by the viewers input from the last part of the form. Does any one know of some thing im missing here? <?php session_start(); // If the session vars aren't set, try to set them with a cookie if (!isset($_SESSION['user_id'])) { if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) { $_SESSION['user_id'] = $_COOKIE['user_id']; $_SESSION['username'] = $_COOKIE['username']; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Social Filter - View Profile</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h3>View Profile</h3> <font size="2"> <?php require_once('appvars.php'); require_once('connectvars.php'); // Make sure the user is logged in before going any further. if (!isset($_SESSION['user_id'])) { echo '<a href="signup.php">Create your own account</a>.</p>'; } else { echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '. <a href="logout.php">Log out</a>.</p>'); } // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the profile data from the database if (!isset($_GET['user_id'])) { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20 FROM mismatch_user WHERE user_id = '" . $_SESSION['user_id'] . "'"; } else { $query = "SELECT username, first_name, last_name, gender, birthdate, city, state, picture, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15, q16, q17, q18, q19, q20 FROM mismatch_user WHERE user_id = '" . $_GET['user_id'] . "'"; } $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The user row was found so display the user data $row = mysqli_fetch_array($data); echo '<table cellpadding="0" cellspacing="0" border="0"><TR><TD> '; if (!empty($row['picture'])) { echo '<table cellpadding="0" cellspacing="0" border="1"><TR><td class="label">Pictu </td><td><img src="' . MM_UPLOADPATH . $row['picture'] . '" width="120" height="140" alt="Profile Picture" /></td></tr></table></td><td>'; } if (!empty($row['username'])) { echo '<table cellpadding="1" cellspacing="0" border="0"><TR><td class="label">Username:</td><td>' . $row['username'] . '</td></tr>'; } if (!empty($row['first_name'])) { echo '<tr><td class="label">First name:</td><td>' . $row['first_name'] . '</td></TR>'; } if (!empty($row['last_name'])) { echo '<tr><td class="label">Last name:</td><td>' . $row['last_name'] . '</td></TR>'; } if (!empty($row['gender'])) { echo '<tr><td class="label">Gender:</td><td>'; if ($row['gender'] == 'M') { echo 'Male'; } else if ($row['gender'] == 'F') { echo 'Female'; } else { echo '?'; } echo '</td></tr>'; } if (!empty($row['birthdate'])) { if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) { // Show the user their own birthdate echo '<tr><td class="label">Birthdate:</td><td>' . $row['birthdate'] . '</td></tr>'; } else { // Show only the birth year for everyone else list($year, $month, $day) = explode('-', $row['birthdate']); echo '<tr><td class="label">Year born:</td><td>' . $year . '</td></tr>'; } } if (!empty($row['city']) || !empty($row['state'])) { echo '<tr><td class="label">Location:</td><td>' . $row['city'] . ', ' . $row['state'] . '</td></tr>'; } echo '</td></tr></table></td></Tr></table><hr></font><FONT color="#666666" size="1" face="Courier"><table cellpadding="20" cellspacing="0" border="0"><tr><td>'; if (!isset($_GET['user_id']) || ($_SESSION['user_id'] == $_GET['user_id'])) { echo '<p>Would you like to <a href="editprofile.php">edit your profile</a>?</p>'; } } // End of check for a single row of user results else { echo '<p class="error">There was a problem accessing your profile.</p>'; } if (!empty($row['q1'])) { echo '1. ' . $row['q1'] . '<BR><input type="radio" name="radio1" id="yes1" value="yes" /> <label for="yes1">YES</label> or <input type="radio" name="radio1" id="no1" value="no" /> <label for="no1">NO</label><BR>'; } else { echo ' User has not made a application yet...<BR>'; } if (!empty($row['q2'])) { echo '2. ' . $row['q2'] . '<BR><input type="radio" name="radio2" id="yes2" value="yes" /> <label for="yes2">YES</label> or <input type="radio" name="radio2" id="no2" value="no" /> <label for="no2">NO</label><BR>'; } else { echo ' <BR>'; } if (!empty($row['q3'])) { echo '3. ' . $row['q3'] . '<BR><input type="radio" name="radio3" id="yes3" value="yes" /> <label for="yes3">YES</label> or <input type="radio" name="radio3" id="no3" value="no" /> <label for="no3">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q4'])) { echo '4. ' . $row['q4'] . '<BR><input type="radio" name="radio4" id="yes4" value="yes" /> <label for="yes4">YES</label> or <input type="radio" name="radio4" id="no4" value="no" /> <label for="no4">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q5'])) { echo '5. ' . $row['q5'] . '<BR><input type="radio" name="radio5" id="yes5" value="yes" /> <label for="yes5">YES</label> or <input type="radio" name="radio5" id="no5" value="no" /> <label for="no5">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q6'])) { echo '6. ' . $row['q6'] . '<BR><input type="radio" name="radio6" id="yes6" value="yes" /> <label for="yes6">YES</label> or <input type="radio" name="radio6" id="no6" value="no" /> <label for="no6">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q7'])) { echo '7. ' . $row['q7'] . '<BR><input type="radio" name="radio7" id="yes7" value="yes" /> <label for="yes7">YES</label> or <input type="radio" name="radio7" id="no7" value="no" /> <label for="no7">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q8'])) { echo '8. ' . $row['q8'] . '<BR><input type="radio" name="radio8" id="yes8" value="yes" /> <label for="yes8">YES</label> or <input type="radio" name="radio8" id="no8" value="no" /> <label for="no8">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q9'])) { echo '9. ' . $row['q9'] . '<BR><input type="radio" name="radio9" id="yes9" value="yes" /> <label for="yes9">YES</label> or <input type="radio" name="radio9" id="no9" value="no" /> <label for="no9">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q10'])) { echo '10. ' . $row['q10'] . '<BR><input type="radio" name="radio10" id="yes10" value="yes" /> <label for="yes10">YES</label> or <input type="radio" name="radio10" id="no10" value="no" /> <label for="no10">NO</label><BR></td><TD>'; } else { echo '<BR></td><td>'; } if (!empty($row['q11'])) { echo '11. ' . $row['q11'] . '<BR><input type="radio" name="radio11" id="yes11" value="yes" /> <label for="yes11">YES</label> or <input type="radio" name="radio11" id="no11" value="no" /> <label for="no11">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q12'])) { echo '12. ' . $row['q12'] . '<BR><input type="radio" name="radio12" id="yes12" value="yes" /> <label for="yes12">YES</label> or <input type="radio" name="radio12" id="no12" value="no" /> <label for="no12">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q13'])) { echo '13. ' . $row['q13'] . '<BR><input type="radio" name="radio13" id="yes13" value="yes" /> <label for="yes13">YES</label> or <input type="radio" name="radio13" id="no13" value="no" /> <label for="no13">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q14'])) { echo '14. ' . $row['q14'] . '<BR><input type="radio" name="radio14" id="yes14" value="yes" /> <label for="yes14">YES</label> or <input type="radio" name="radio14" id="no14" value="no" /> <label for="no14">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q15'])) { echo '15. ' . $row['q15'] . '<BR><input type="radio" name="radio15" id="yes15" value="yes" /> <label for="yes15">YES</label> or <input type="radio" name="radio15" id="no15" value="no" /> <label for="no15">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q16'])) { echo '16. ' . $row['q16'] . '<BR><input type="radio" name="radio16" id="yes16" value="yes" /> <label for="yes16">YES</label> or <input type="radio" name="radio17" id="no16" value="no" /> <label for="no16">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q17'])) { echo '17. ' . $row['q17'] . '<BR><input type="radio" name="radio17" id="yes17" value="yes" /> <label for="yes17">YES</label> or <input type="radio" name="radio17" id="no17" value="no" /> <label for="no17">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q18'])) { echo '18. ' . $row['q18'] . '<BR><input type="radio" name="radio18" id="yes18" value="yes" /> <label for="yes18">YES</label> or <input type="radio" name="radio18" id="no18" value="no" /> <label for="no18">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q19'])) { echo '19. ' . $row['q19'] . '<BR><input type="radio" name="radio19" id="yes19" value="yes" /> <label for="yes19">YES</label> or <input type="radio" name="radio19" id="no19" value="no" /> <label for="no19">NO</label><BR>'; } else { echo '<BR>'; } if (!empty($row['q20'])) { echo '20. ' . $row['q20'] . '<BR><input type="radio" name="radio20" id="yes20" value="yes" /> <label for="yes20">YES</label> or <input type="radio" name="radio20" id="no20" value="no" /> <label for="no20">NO</label><BR></td><td></font></font>'; } else { echo '<BR></td><td valign="top"></font></font><FONT color="#000000" size="1">'; } mysqli_close($dbc); ?> <script> function autotab(original,destination){ if (original.getAttribute&&original.value.length==original.getAttribute("maxlength")) destination.focus() } </script> <fieldset> <legend>Your Contact Information</legend> </font></font><FONT color="#cccc99" size="2" face="Impact"> <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table width="100%" border="0" cellpadding="2"> <tr> <td><div align="right"> <label for="vieweremail">Email</label> </div></td> <td><div align="left"> <input name="vieweremail" type="text" id="vieweremail" size="35" maxlength="90" /> </div></td> </tr> <tr> <td><div align="right"> <label for="veiwername">Name</label> </div></td> <td><div align="left"> <input name="veiwername" type="text" id="veiwername" size="35" maxlength="100" /> </div></td> </tr> <tr> <td><div align="right"> <label for="viewerphone">Phone Number</label> </div></td> <td><div align="left"> <input name="Phone1" type="text" id="phone1" onkeyup="autotab(this, document.form1.phone2)" size="3" maxlength="3" /> <input name="phone2" type="text" id="phone2" onKeyup="autotab(this, document.form1.phone3)" size="3" maxlength="3" /> <input name="phone3" type="text" id="phone3" onKeyup="autotab(this, document.form1.viewercomments)" size="4" maxlength="4" /> </div></td> </tr> <tr> <td><div align="right"> <label for="viewercomments">Comments</label> </div></td> <td><div align="left"> <textarea name="viewercomments" cols="26" rows="4" id="viewercomments"></textarea> </div></td> </tr> <tr> <td><div align="right"> <label for="viewerpic">Your Picture (optional)</label> </div></td> <td><div align="left"> <input name="viewerpic" type="file" id="viewerpic" size="22" /> </div></td> </tr> <tr> <td><div align="right"> <label for="clear"></label> <input type="reset" name="clear" id="clear" value="Clear Form!" /> </div></td> <td><div align="left"> <label for="submit"></label> <input type="submit" name="submit" id="submit" value="Send Email" /> </div></td> </tr> </table> </form> </fieldset> <BR><BR><BR><BR><BR><BR> </td></tr></table> </body> </html> Here is the send mail script im using.... trying to anyways.<?php require_once('appvars.php'); require_once('connectvars.php'); // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (isset($_POST['submit'])) { $from = 'cupid@cupidsomething.com'; $subject = $_POST['subject']; $text = $_POST['q1, q2,q3,q4....ect...etc....cet.....eece.c.']; $output_form = false; if (empty($subject) && empty($text)) { echo 'You forgot the email subject and body text.<br />'; $output_form = true; } if (empty($subject) && (!empty($text))) { echo 'You forgot the email subject.<br />'; $output_form = true; } if ((!empty($subject)) && empty($text)) { echo 'You forgot the email body text.<br />'; $output_form = true; } } else { $output_form = true; } if ((!empty($subject)) && (!empty($text))) { $query = "SELECT user_id FROM email_list WHERE user_id = '$user_id'; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)){ $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = "Dear $first_name $last_name,\n$text"; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $first_name . '<br />'; } mysqli_close($dbc); } if ($output_form) { ?> Any help would be greeeeatly appreciated. Here is a live example of this at www.interestingspecies.com/mismatch/20 Similar TutorialsHi all, What I am trying to achieve is, I thought quite simple! Basically, a user signs up and chooses a package, form is submitted, details added to the database, email sent to customer, then I want to direct them to a paypal payment screen, this is where I am having issues! Is their any way in php to submit a form without user interaction? Here is my code for the form process page Code: [Select] <?php include('config.php'); require('scripts/class.phpmailer.php'); $package = $_POST['select1']; $name = $_POST['name']; $email = $_POST['email']; $password = md5($_POST['password']); $domain = $_POST['domain']; $a_username = $_POST['a_username']; $a_password = $_POST['a_password']; $query=mysql_query("INSERT INTO orders (package, name, email, password, domain, a_username, a_password) VALUES ('$package', '$name', '$email', '$password', '$domain', '$a_username', '$a_password')"); if (!$query) { echo "fail<br>"; echo mysql_error(); } else { $id = mysql_insert_id(); $query1=mysql_query("INSERT INTO customers (id, name, email, password) values ('$id', '$name', '$email', '$password')"); if (!$query1) { echo "fail<br>"; echo mysql_error(); } if($package=="Reseller Hosting") { //email stuff here - all works - just cutting it to keep the code short if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } ?> <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="subscription@jollyhosting.com"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_name" value="Jolly Hosting Reseller Packages"> <input type="hidden" name="no_shipping" value="1"> <!--1st month --> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="a3" value="3.00"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> <input type="hidden" name="sra" value="1"> </form>'; <?php } //last } //end ?> sendmail.php Code: [Select] <?php $email = $_POST['email']; $to = $_POST['recipent']; $subject = "SUBJECT HERE."; $message = "YOUR MESSAGE HERE"; $header = "From: $email " . "\r\n"; $send = mail($to, $subject, $message, $header); echo "Your invitations have been sent!"; ?> and this is invite.php Code: [Select] <style> #container_mail { width:300px; margin:0 auto; background:#151521; padding:5px; background-color:#ffffff; border:1px solid black; /* for IE */ filter:alpha(opacity=60); /* CSS3 standard */ opacity:0.6; } #inner_container_mail { background:url(../images/inner_container.jpg) top repeat-x #181824; padding:10px 10px 10px 25px; } </style> <?php include_once 'common.php'; require_once("pages/validation.php"); ?> <script type="text/javascript" src="ajax/jquery.js"></script> <div id="container_mail"> <div id="inner_container_mail"> <div id="content"> <?if( isset($_POST['send']) && (!validateEmail($_POST['email']) ) ):?> <div id="error"> <ul> <?if(!validateEmail($_POST['email'])):?> <li><strong><?=$errormail?></strong> <?=$errormail1?></li> <?endif?> </ul> </div> <?elseif(isset($_POST['send'])):?> <div id="error" class="valid"> <ul> <li><strong><?=$congratulations?></strong> <?=$congratulations?></li> </ul> </div> <p> <?endif?> </p> <form method="post" id="customForm" action="pages/invite_mail.php"> <div> <label for="email"><?= $email; ?></label> <input id="email" name="email" type="text" /> <span id="emailInfo"><?= $yourmail; ?></span> </div> <div> <label for="recipent"><?= $email; ?></label> <input id="recipent" name="recipent" type="text" /> <span id="emailInfo"><?= $yourmail; ?></span> </div> <div> <input id="send" name="send" type="submit" value="<?=$submit;?>" /> </div> </form> </div> <script type="text/javascript" src="ajax/jquery.js"></script> <script type="text/javascript" src="ajax/validation_email.js"></script> </body> </html> </div> </div> </div> </body> </html> how to send the corent location in website to friend for example now my location is http://www.phpfreaks.com/forums/index.php?action=post;board=1.0 how to send this ? sorry for my english .. Hi, I've created a basic form which uploads a document to my server. How do I generate an email with the uploaded document as an attachment? Here's the HTML: <form enctype="multipart/form-data" action="form1.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> Here's the PHP: <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Thanks in advance! I am brand new at php coding so I am struggling to understand why my php code is not working in my website. I would like my html form to send me data to my email. Whatever I try, it just will not work. I have ftp'ed it to my website and I checked with my web host, they do support php. Anyone who can help out a newbie, please?
This is my very simple form to capture email addresses of new clients: <form action="send_mail.php" method="post"> <input name="Email"
placeholder="Enter your email..." required="" type="email"> This is the php coding I have placed in a document called send_mail.php:
<?php /* Code: [Select] <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $dropdown = $_POST['dropdown']; $formcontent=" From: $firstname \n Surname: $lastname \n Email: $email \n Dropdown: $dropdown"; $recipient = "martin@sittingspiritually.co.uk, siobhan@sittingspiritually.co.uk"; $subject = "Newsletter Sign Up"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); if ( mail($recipient, $subject, $formcontent, $mailheader) ){ header('Location: http://www.sittingspiritually.co.uk/thankyou.php'); } else { die ("error"); } ?> I have recently created a small snippet of php code for posting mail and it's sweet apart from 1 thing. I have two email addresses in the recipient section. It only sends to the last name in the list. Is this because i have written recipient? Should it be recipients? I need this mail to be delivered to both of the email addresses. I'm sure it's simple for someone with expert knowledge. Thanks in advance for any help. if anyone out there fancy's helping the needy please can you cast your eyes over my mess! and possibly help me find my way out of this maze? So im useing a third party form, and a third party php script.......... cant get them to work together . form script : [color=red//-------------------------------------------------[/color] <form action="phpquote.php" method="post" id="reserve-form"> <div class="box"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="border-top"></div> </div> </div> <div class="border-left"> <div class="border-right"> <div class="xcontent"> <h5>Get an online quote for your journey</h5> <p>please fill in all fields for your quote.</p> <fieldset> <div class="field"> <label>Customer Information</label> <input type="text" id="name" value="Name" onblur="if(this.value==''){this.value='Name'}" onfocus="if(this.value=='Name'){this.value=''}" /> </div> <div> <input type="text" id="number" value="Phone" onblur="if(this.value==''){this.value='Phone'}" onfocus="if(this.value=='Phone'){this.value=''}" /> </div> </fieldset> <fieldset class="style1"> <div class="field"> <label>Travel Date/ Time</label> <select id="year"> <option>2010</option> <option>2011</option> </select> <select class="sel-1" id="month"> <option>Jan</option> <option>Feb</option> <option>Mar</option> <option>Apr</option> <option>May</option> <option>Jun</option> <option>Jul</option> <option>Aug</option> <option>Oct</option> <option>Sep</option> <option>Nov</option> <option>Dec</option> </select> <select class="sel-2" id="date"> <option>1</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> </select> </div> <div class="field"> <select class="sel-2" id="time"> <option>00</option> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option></select> <select class="sel-2" id="time"> <option>00</option> <option>15</option> <option>30</option> <option>45</option> </select> </div> <div class="field"> <label>No. Passangers</label> <select id="year"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> </select> </div> </fieldset> <fieldset class="style2"> <div class="field"> <label>Pickup Information</label> <input type="text" id="where" value="Pickup Address" onblur="if(this.value==''){this.value='Pickup Address'}" onfocus="if(this.value=='Pickup Address'){this.value=''}" /> </div> <div> <select id="where"> <option>or Airport</option> <option>Stansted</option> <option>Gatwick</option> <option>Heathrow</option> <option>Luton</option> </select> </div> </fieldset> <fieldset class="style2 style3"> <div class="field"> <label>Drop-off Information</label> <input type="text" id="to" value="Drop-off Address" onblur="if(this.value==''){this.value='Drop-off Address'}" onfocus="if(this.value=='Drop-off Address'){this.value=''}" /> </div> <div> <select id="to"> <option>or Airport</option> <option>Stansted</option> <option>Gatwick</option> <option>Heathrow</option> <option>Luton</option> </select> </div> </fieldset> </div> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"><a href="#" class="link2" onclick="document.getElementById('reserve-form').submit()"><em><b>Get Quote</b></em></a></div> </div> </div> </div> </form> //----------------------------------------------------------------------------- php script //----------------------------------------------------------------------------- <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'Results from Contact form'; // Your email address. This is where the form information will be sent. $emailadd = 'm.mcdade@hotmail.co.uk'; // Where to redirect after form is processed. $url = 'http://www.mock.thetaxirank.co.uk/thankyou.html'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> //----------------------------------------------------------------------------- any advice will be appreciated..... thanks in advance to any kind souls !!! I have a contact form with a file upload button, when you click on “submit” you are redirected on Paypal everything works fine but, I would like to send the contact form only when visitors have paid on Paypal. I’ve searched on google but I have not found a way to do this. Can anyone help? Cheers, Aidan. Hello all, I used simple php email function but it send an email in junk folder or spam. Can anyone tell me why is this so? Her is the code: $host = "ssl://smtp.gmail.com"; $port = "465"; $to = " xx@gmail.com"; // note the comma $subject = " $_POST[company_website] "; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: About Wholesale Account' . "<$_POST[email]>\r\n"; $headers .= 'Cc: mail@gmail.com' . "\r\n"; $headers .= 'Bcc: cc@gmail.com' . "\r\n"; mail($to, $subject, $message, $headers); The PHP code sends me an email from the server, but the user input is empty or "blank". I only receive: "From: \ Email: \ Subject: \ Message: " and that's it. How do I fix my PHP and/or HTML code to receive user input from the form? Attached is my existing HTML and PHP code that doesn't send me any "user input" from the form. Thanks to anyone who can help!!
Hello Guys,
I need your help as many PHPers here is more experienced in PHP coding than me. I have specific project I am working on and need a piece of code that can send an email from HTML form using PHP to the email address that is entered manually on the form, instead of standard sent to PHP code that is fixed within PHP script and executed during submission. I want sth that can grab manually enetered recipient's e-mail address, paste it to the PHP code and then use it to send the email to the recipient, instead of fixed sent to code. Something would say dynamically changed during the entry that can inject into PHP code the new address email entered on the form and then submit to it. Any ideas will be great.
Thanks.
Edited March 27, 2019 by slawotrend
The code below currently sends a separate Email with data from each row of a table when a Save All button is pressed. So, if I have 4 rows of data, 4 Email will be sent. $email="to@email.com"; $from="from@email.com"; $msg=""; $subject="Registers Info for: ".$values["first_name"]." ".$values["last_name"].""; $msg.= "Student: ".$values["first_name"]." ".$values["last_name"]."\r\n"; $msg.= "Absent or Present: ".$values["attendance_status"]."\r\n"; $msg.= "Class: ".$values["classname"]."\r\n"; $msg.= "Class Date: ".$values["attendance_date"]."\r\n"; $msg.= "Amount Received: ".$values["cash_received"]."\r\n"; $msg.= "Paid For: ".$values["cash_whatfor"]."\r\n"; $ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from)); if(!$ret["Sent"]) echo $ret["message"];
Edited February 27, 2020 by leemo Hi, This is driving me to distraction. I have been using this code Code: [Select] <?php $mailto = "edwin@btconnect.com"; $subject = "enquiry"; $message = "Values submitted from web site form:"; $header = "From: ".$_POST['email']; foreach ($_POST as $key => $value) { if (!is_array($value)) { $message .= "\n".$key." : ".$value; } else { foreach ($_POST[$key] as $itemvalue) { $message .= "\n".$key." : ".$itemvalue; } } } mail($mailto, $subject, stripslashes($message), $header); ?> very successfully but now I want to receive information from a 'textarea' in a form but it just doesn't get treated as input. The form is here; <form name="enquiry" method="post" action="feedback.php"> <tr> <td align="left">Name:</td> <td align="right"><input type="text" name="name" size="25" value=""></td> </tr> <tr> <td align="left">email:</td> <td align="right"><input type="text" name="email" size="25" value=""></td> </tr> <tr> <td align="left" valign="top">Blurb:</td> <td align="right"><textarea rows="4" cols="19" value=""></textarea></td> </tr> <tr><td colspan="2" align="right"> <input name="submit" type="image" src="report.gif" width="40" height="20" border="0"> </td></tr></form> Can anyone please help? edwind Hello, i have been looking for and answer on the internet but i couldn't find it! I'm new on PHP based on and example i wrote something like this for my website: //basic variables $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "example@mysite.org"; $Subject = "Registration u10"; $teamname = Trim(stripslashes($_POST['teamname'])); $affiliation = Trim(stripslashes($_POST['affiliation'])); $premier = Trim(stripslashes($_POST['premier'])); $challenge = Trim(stripslashes($_POST['challenge'])); $girls = Trim(stripslashes($_POST['girls'])); $boys = Trim(stripslashes($_POST['boys'])); //about 15 more variables go in here but i don't want to put them to save some space // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // email body text //this includes the info of all the variables at the top even the ones I didn't write in here (but you get the point ) $Body = ""; $Body .= "Team Name: "; $Body .= $teamname; $Body .= "\n"; $Body .= "\n"; $Body .= "AYSleague: "; $Body .= $aysleague; $Body .= "\n"; $Body .= "\n"; $Body .= "Flash Tournament: "; $Body .= $flashtournament; $Body .= "\n"; $Body .= "\n"; $Body .= "Spring 2011: "; $Body .= $spring2011; $Body .= "\n"; $Body .= "\n"; $Body .= "Summer 2011: "; $Body .= $summer2011; $Body .= "\n"; $Body .= "\n"; $Body .= "fall 2011: "; $Body .= $fall2011; $Body .= "\n"; $Body .= "\n"; // send email to my inbox with the information above $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // if everything goes OK it will redirect them to another page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=thanksu12.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">"; } ?> the problem that i have is: (i divided it in 2 sections) 1- i need to sent a second email to the coach 2- that email only needs to have the information of 6 variables not the whole thing I don't know how to do it, if someone knows how to do it, i will appreciate some help!! thanks! Hi guys, i have a custom made php that collect all the info in admin page (long story short), there's a button called "Approve" I would like to send back an email to user who applied with picture, once Approved button is pressed, so here's the script: <?php session_start(); $user = '123'; $pass = '123'; $to = $data['email']; $subject = 'blablabla'; $message = 'test123'; if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pass) { header('WWW-Authenticate: Basic realm="Enter password to access this page."'); header('HTTP/1.0 401 Unauthorized'); echo"You must be logged in to see this page."; exit; } ################## PROTECTED CONTENT ######################## require('./config.php'); ?> <!DOCTYPE HTML> <html> <head> <title>ADMIN PANEL</title> <style type="text/css"> body{width: 960px; margin: auto; margin-top: 20px; padding: 5px 20px; box-shadow: 0px 0px 2px #000000; border-radius: 5px;background:transparent url(images/bg_header.gif) top left repeat-x;} a:link,a:active,a:visited{color: inherit; text-decoration: none;} a:hover{text-decoration: underline;} .button{background:transparent url(images/grad.PNG) bottom left repeat-x; padding: 3px 5px; border-radius: 4px; border: 1px solid #cccccc;} .button:hover{border-color:orangered;text-decoration:none;} .approve .img{max-height: 200px; max-width: 200px; position: absolute; right: 5px; top: 5px;} .approve{display: block; height: 200px; overflow: hidden; box-shadow: 0px 0px 2px #000000; margin-top: 20px; padding: 20px; position: relative; font:13px verdana;} textarea,input{padding: 3px;font: 13px helvetica,verdana;border:1px solid rgb(51,151,251);border-radius: 4px;width: 300px; display: block; margin: 5px 0px;} input:hover,textarea:hover{border-color:orangered;cursor:pointer;} form{font:bold 13px verdana;} input[type='submit'],input[type='button']{width: auto;} </style> </head> <body> <?php echo" <div id='head'> <h1 align='center'>ADMIN PANEL</h1> <h4 align='center'><a href='index.php' class='button'>Homepage</a> <a class='button' href='admin.php'>Approval Queue</a> <a class='button' href='admin.php?edit'>Edit Image info.</a> <a class='button' href='?edit&view'>View Image Info.</a></h4> </div>"; if (isset($_GET['edit'])) { if (isset($_GET['pid'])) { $pic = mysql_query('SELECT * from `' . $table_name . '` WHERE pid = ' . intval($_GET['pid'])); if (mysql_num_rows($pic) == 1) { if (isset($_POST['submit'])) { $approved = isset($_POST['approved']) && $_POST['approved'] == '1' ? 1 : 0; mysql_query('UPDATE `' . $table_name . '` SET ' . 'first_name = "' . $_POST['first'] . '",' . 'last_name="' . $_POST['last'] . '",' . 'phone="' . $_POST['phone'] . '",' . 'email="' . $_POST['email'] . '",' . 'first_name="' . $_POST['first'] . '",' . 'approved=' . $approved . ',' . 'address="' . $_POST['addr'] . '",' . 'admin_desc="' . $_POST['admin_desc'] . '"' . ' WHERE pid = ' . intval($_GET['pid'])) or exit("Unable to edit" . mysql_error()); echo'<h3>EDITED</h3>'; $pic = mysql_query('SELECT * from `' . $table_name . '` WHERE pid = ' . intval($_GET['pid'])); } $data = mysql_fetch_array($pic); if (isset($_GET['view'])) { echo' <strong>Uploaded by </strong>' . $data['first_name'] . ' ' . $data['last_name'] . ' <br /> <img src="' . $default_dir . $data['image_name'] . '" style="max-width: 200px; max-height:200px; float: right;" /> <br /> <br /> <b>First_name :</b> ' . $data['first_name'] . ' <br /> <br /> <b>Last_name :</b> ' . $data['last_name'] . ' <br /> <br /> <b>Phone :</b> ' . $data['phone'] . ' <br /> <br /> <b>Email :</b> ' . $data['email'] . ' <br /> <br /> <b>Approved :</b> ' . ($data['approved'] == 1 ? 'Yes' : 'No') . ' <br /> <br /> <b>Address :</b> ' . $data['address'] . ' <br /> <br /> <b>Admin_description :</b> <br /> <br />' . $data['admin_desc'] . ' <br /> <br /> <a href="?edit&pid=' . $data['pid'] . '" class="button">Edit</a> <br /> <br /> '; } else { echo'<form method="POST" action="?edit&pid=' . intval($_GET['pid']) . '"> Editting photo: <a style="color:rgb(51,151,251);" href="' . $default_dir . $data['image_name'] . '">' . $data['image_name'] . '</a> uploaded by ' . $data['first_name'] . ' ' . $data['last_name'] . ' <br /> <img src="' . $default_dir . $data['image_name'] . '" style="max-width: 200px; max-height:200px; float: right;" /> <br /> First_name : <input type="text" name="first" value="' . $data['first_name'] . '" /> Last_name : <input type="text" name="last" value="' . $data['last_name'] . '" /> Phone : <input type="text" name="phone" value="' . $data['phone'] . '" /> Email : <input type="text" name="email" value="' . $data['email'] . '" /> Approved : <input type="text" name="approved" value="' . $data['approved'] . '" /> 0 or 1 Address : <textarea name="addr">' . $data['address'] . '</textarea> Admin_description : <textarea name="admin_desc">' . $data['admin_desc'] . '</textarea> <input type="submit" name="submit" value="Edit" /> </form>'; } } else { echo"NO SUCH PICTURE EXISTS"; } } else { echo" <h3>Search for image to " . (isset($_GET['view']) ? 'view' : 'edit') . " it: </h3> <form id='form' method='POST' action='admin.php?edit" . (isset($_GET['view']) ? '&view' : '') . "'> Uploader's first name: <input type='text' name='name' value='' /> OR Image name: <input type='text' name='img' value='' /> OR Email: <input type='text' name='email' value='' /> <input type='submit' name='submit' value='Search' /> </form>"; if (isset($_POST['submit'])) { $name = empty($_POST['name']) ? '%' : '%' . $_POST['name'] . '%'; $email = empty($_POST['email']) ? '%' : '%' . $_POST['email'] . '%'; $img = empty($_POST['img']) ? '%' : '%' . $_POST['img'] . '%'; $query = mysql_query( 'SELECT * from `' . $table_name . '` where ' . 'first_name like "' . $name . '" and ' . 'email like "' . $email . '" and ' . 'image_name like "' . $img . '"'); if (mysql_num_rows($query) > 0) { while ($pic = mysql_fetch_array($query)) { echo"<hr/><strong>Uploaded by $pic[first_name] $pic[last_name] " . date(' \a\t H:i \o\n d/m/Y', intval($pic['image_name'])) . "</strong> - <a href='$default_dir$pic[image_name]' target='_blank'>$pic[image_name]</a> <a href='?edit" . (isset($_GET['view']) ? '&view' : '') . "&pid=$pic[pid]' class='button'>" . (isset($_GET['view']) ? 'View' : 'Edit') . "</a>"; } } else { echo "NO IMAGE MATCHES THAT DESCRIPTION"; } } } exit; } if (isset($_GET['approve'])) { if (mysql_query('UPDATE `' . $table_name . '` SET approved = 1 WHERE pid = ' . intval($_GET['approve']))) { if (@mail($to, $subject, $message)) { echo('<p>Mail sent successfully.</p>'); } else { echo('<p>Mail could not be sent.</p>'); } echo"<h2>APPROVEDs</h2>"; } } It's not whole script though. i wrote this code <?php $mail_to='XXX@gmail.com'; $subject_mail='UYYYY'; $message='XXXXX'; $headers = "MIME-Version: 1.0 \r\n"; $headers .= "Content-type: text/html; charset=UTF-8 \r\n"; $headers .= "From: XXX@gmail.com \r\n"; mail($mail_to, $subject_mail, $message, $headers ); ?> but the email will not send why please? Hello, I have a registration page and when a user registers I want to send their email an activation code. To test I have the following code. <?php //Send activation Email $to = $Email_address; $subject = "www.WEBSITE.com/"; $message = "Welcome to my website!\r\rYou, or someone using your email address, has completed registration at WEBSITE. You can complete registration by clicking the following link:\rhttp://www.WEBSITE.com/register.php?action=verify&$activationKey\r\r If this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\ "; $headers = 'From: noreply@abc.com' . "\r\n" . 'Reply-To: noreply@abc.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); if (mail($to, $subject, $message, $headers)) { echo 'Success'; } else { echo 'Error'; } ?> I have the last if else to see if it is sent to not. I do get a Success message, but I don't get an email at the address (I have checked the spam folder). I have checked the email address and it is correct. I have even waited a few hours and nothing. Why is the email not getting to my account? Hi I have a form that I want people to fill out and then click the button and it sends me an email. My problem is that it doesn't send me any emails, I have looked around and I don't seem to find any thing. This is my form in application_form.php Code: [Select] <form action="application_form" method="POST"> <table border="0" cellpadding="5" cellspacing="0"> <tr> <td>Full name</td> <td><input type="text" size="30" maxlength="80" name="name" /></td> </tr> <tr> <td>Email address</td> <td><input type="text" size="30" maxlength="80" name="email" /></td> </tr> <tr> <td>Message</td> <td><textarea name="message" cols="29" rows="5"></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Submit Message" /></td> </tr> </table> </form> and this is the php on the same application_form.php Code: [Select] <?php if (isset($_POST['submit'])) { // Collect variables $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; // Send email $body = "The following feedback has been submitted:\n\n"; $body .= "Name: $name\n"; $body .= "Email: $email\n"; $body .= "Message: $message"; mail ("cerberus478@gmail.com","Feedback Received",$body,"From: cerberus478@gmail.com"); // Output confirmation echo "<p>Your message has been received.</p>"; } ?> Hello Im making html mail for my project. However the mail() function of PHP does not send my email. Code: [Select] <?php $message = ' <html> <head> <title>Test Email</title> </head> <body> <h4>This is a test email message from me</h4> <br/> <p><b>Lorem Ipsum<b><br/> is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> </body> </html> '; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'To: me <darkstarnexus@yahoo.com>' . "\r\n"; $headers .= 'From: Sample <sample@mail.com>' . "\r\n"; $headers .= 'Cc: Sample2 <sample2@mail>' . "\r\n"; $headers .= 'Bcc: sample3@mail' . "\r\n"; if(mail('darkstarnexus@yahoo.com', 'Test Html Email', $message, $headers)){ echo "mail delivered"; }else{echo "mail is not delivered";} ?> Can some tell me why? Okay, I got the other parts of this script to input the form information into my database, but this part of the code is not sending the user the activation email. Please Help!? I've attached the complete script for an extra pair of eyes. Thanks /!!!!!!!!!!!!!!!!!!!!!!!!! Email User the activation link !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $myemail = "admin@knirv.com"; $emess = "First Name: $firstname\n"; $emess.= "Last Name: $lastname\n"; $emess.= "Email 1: $email1\n"; $emess.= "Email 2: $email2\n"; $emess.= "City: $city\nState: $state\nZip/Post Code:$zip\n"; $emess.= "Country: $scountry\n"; $emess.= "Phone number 1: $phone1\n"; $emess.= "Phone number 2: $phone2\n"; $emess.= "Phone number 3: $phone3\n"; $emess.= "Comments: $sendmail"; $ehead = "From: $myemail\r\n"; $subj = "Complete knirv.com registration!"; $mailsend=mail("$myemail","$subj","$emess","$ehead"); //Begin HTML Email Message $message = "Hi $firstname, Complete this step to activate your login identity at knirv.com. Click the line below to activate when ready. http://www.knirv.com/activation.php?id=$id&sequence=$db_password If the URL above is not an active link, please copy and paste it into your browser address bar Login after successful activation using your: E-mail Address: $email Password: $password See you on the site! admin@knirv.com"; //end of message unset($_GET['do']); header("Location: thank_you.php"); break; } $msgToUser = "<h2>One Last Step - Activate through Email</h2><h4>OK $firstname, one last step to verify your email identity:</h4><br /> In a moment you will be sent an Activation link to your email address.<br /><br /> <br /> <strong><font color=\"#990000\">VERY IMPORTANT:</font></strong> If you check your email with your host providers default email application, there may be issues with seeing the email contents. If this happens to you and you cannot read the message to activate, download the file and open using a text editor. If you still cannot see the activation link, contact site admin and briefly discuss the issue.<br /><br /> "; include_once 'msgToUser.php'; exit(); } |