PHP - Php Send Mail Error With Multi-line Messages
Similar TutorialsI am trying to send an e-mail message from a form, to each person in a MySQL database. In some cases, but not all, there are multiple e-mail address in the recordset. Each one should receive the same message addressed to them by name (FirstName and LastName) and e-mail address. I have tried "CONCAT_WS(' ', emailtest.Pri_EmailAddress, emailtest.Sec_EmailAddress, emailtest.Tri_EmailAddress) AS EmailTo" but it seems the relay account is rejecting the message if more than one address is in the EmailTo result. Any ideas or scripts that can do this would be appreciated. Thank you in advance for your help. Hi guys please i need your help . i created a HTML/PHP form . The PHP form handles posting to my mail while the HTML is the front face / webpage . Anyway i created a form that has fields such as name (textbox), email(textbox) , inquiry(textarea) , state (textbox) country (dropdown list ) , how did you find us (dropdown list). However whenever i test the form all it posts to my mailbox is name , email , inquiry . Please how do i make the other fields get recognized / how do i get the details in the other fields to be posted to my mailbox. How is it possible, in PHP, to display an error message next to a form input text field if a user is attempting to submit a form with empty fields? Moreover, how is it possible to remove the same error message when the user fills in the input field with the required data and/or refreshes the page? I have 2 files that I am working with: application.php and process.php.
application.php mainly has the HTML of the form. I am very new to learning PHP (I started learning it last week) and I have been searching for hours for a clear answer. I have already tried different methods for generating the error message including: using empty(), !isset, $_POST["name"] = "", etc, and have tried using session_start();, $row, echo, print, and other variables to try and display error message on the page, and I have tried using unset();, and = null, to try and remove the error message once the input field has been filled but all to no avail. Either the method I try only half works, or nothing works, and I cannot pinpoint which is the part that is not working. I only have 2 files to work with, and as an example of what I want to do is:
1. If the first name field is empty when the user clicks submit, an error message should appear next to the input. Is this possible with PHP? This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 Guys, give me an idea of using a free or open sorce software for transferring messages over a local network between computers using MAC OS and Linux platforms.
Let me make this clear really quick, I am not talking about this forum. Ok, so how do I set up a way that I can make a simple messaging system on my website and make it so that I can have check boxes of who I can send a message to on my website. I have a recipient field and I need to know how I can make it so that only the specific members that are checked will get the message.........does this make sense? is there a function that can send text messages using php? thru an sms modem? Dear All Good Day, i am new to PHP (a beautiful server side scripting language). i want to send a mail with line by line message i tried with different types like by placing the things in table and using <br /> but the thing is the tags are also visible in the message of the mail. Here is my code: $message1 = "Name :". $_REQUEST['name']."<br />"; $message1 .= "Surname :". $_REQUEST['surname']."<br />"; $message1 .= "Cellphone :". $_REQUEST['mobileno']."<br />"; $message1 .= "Telephone :". $_REQUEST['landno']."<br />"; $message1 .= "Fax :". $_REQUEST['fax']."<br />"; $message1 .= "Company :". $_REQUEST['company']."<br />"; $message1 .= "Email :". $_REQUEST['email']."<br />"; $message1 .= "Country :". $_REQUEST['country']."<br />"; $message1 .= "Enquity :". $_REQUEST['enquiry']."<br />"; $message1 .= "Date&Time :". $date."<br />"; For this code if try to print/echo it it is working fine it is displaying line by line, but using this variable ($message1) in the mail these <br /> are also visible. Can any one guide me to resolve(to remove these tags from the message part) this issue. Thanks in Advance. :confused: I have to get the error messages to appear...but for some reason they're not showing up if I leave the forms blank and click submit. Code: [Select] <? $PROVINCES = array( "--" => "--- Please Select Provinces ---", "nf"=>"Newfoundland", "pe"=>"Prince Edward Island", "nb"=>"New Brunswick", "ns"=>"Nova Scotia", "qc"=>"Quebec", "on"=>"Ontario", "mb"=>"Manitoba", "sk"=>"Saskatchewan", "ab"=>"Alberta", "bc"=>"British Columbia", "nt"=>"Northwest Territories"); if ($_SERVER['REQUEST_METHOD'] == 'GET') { $dimwelcomeMsg = TRUE; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['uname'] == ''){ $errMsg['uname'] = "Username must not be blank!!!"; $unameInError = true; } if (empty($_POST['year']) == TRUE){ $errMsg['year'] = "Year must not be blank!!"; } if (count($errMsg) > 0 ): $dispErrorMsg = TRUE; else: foreach ($_POST as $key => $val): $key = strtoupper($key); $successMsg[$key] = $val; endforeach; $dispSuccessMsg = TRUE; endif; } ?> <html > <head> <title>Comp10065 - Simple Form Validatioon</title> <style type="text/css"> body { margin: 0; padding: 0; font: 80%/1.5 Arial,Helvetica,sans-serif; color: #111; background-color: green; } h2 { margin: 0px; padding: 10px; font-family: Georgia, "Times New Roman", Times, serif; font-size: 200%; font-weight: normal; color: #FFF; background-color: #CCC; border-bottom: #BBB 2px solid; } h1 {color:#006600} p#copyright { margin: 20px 10px; font-size: 90%; color: #999; } div.form-container { margin: 10px; padding: 5px; background-color: #FFF; border: #EEE 1px solid; } p.legend { margin-bottom: 1em; } p.legend em { color: #C00; font-style: normal; } div.errors { margin: 0 0 10px 0; padding: 5px 10px; border: #FC6 1px solid; background-color: #FFC; } div.errors p { margin: 0; } div.errors p em { color: #C00; font-style: normal; font-weight: bold; } div.success { margin: 0 0 10px 0; padding: 5px 10px; border: #FC6 1px solid; background-color: #FFC; } div.success p { margin: 0; color:#006633} div.success li {list-style-type: none; } div.form-container form p { margin: 0; } div.form-container form p.note { margin-left: 170px; font-size: 90%; color: #333; } div.form-container form fieldset { margin: 10px 0; padding: 10px; border: #DDD 1px solid; } div.form-container form legend { font-weight: bold; color: #666; } div.form-container form fieldset div { padding: 0.25em 0; } div.form-container label, div.form-container span.label { margin-right: 10px; padding-right: 10px; width: 150px; display: block; float: left; text-align: right; position: relative; } div.form-container label.error, div.form-container span.error { color: #000; } div.form-container select.error, div.form-container div.error {background-color: #FEF;} div.form-container label em, div.form-container span.label em { position: absolute; right: 0; font-size: 120%; font-style: normal; color: #C00; } div.form-container input.error { border-color: #C00; background-color: #FEF; } div.form-container input:focus, div.form-container input.error:focus, div.form-container textarea:focus { background-color: #FFC; border-color: #FC6; } div.form-container div.controlset {margin: 3px} div.form-container div.controlset label, div.form-container div.controlset input { display: inline; float: none; } div.form-container div.controlset div { margin-left: 170px; } div.form-container div.buttonrow { padding-left: 430px; border: 1px solid #CCCCCC } div#wrapper {width: 700px ; margin-left: auto; margin-right: auto} pre {color:black; font-size: 10pt; font-weight: bold; margin-left: 30px} </style> </head> <body> <div id="wrapper"> <h1> Form Validation Lab</h1> <div class="form-container"> <? if ($_SERVER['REQUEST_METHOD'] == 'GET') : ?> <? if (displayWelcomeMsg) : ?> <p>Please fill in the form........</p> <? endif; ?> <? endif; ?> <? if ($displaySuccessMsg): ?> <div class="success"> <p>Thank you for your submission.</p> <ol> <? foreach($successMsgs as $key => $successMsg): ?> <li><?= $key ?> = <?= $successMsg ?> </li> <? endforeach; ?> </ol> </div> <? endif; ?> <? if ($dispErrorMsg) : ?> <div class="errors"> <p><em>Oops...the following errors were encountered</em></p> <ul> <? foreach ($errMsgs as $key => $errMsg): ?> <li><?= $errMsg ?> </li> <? endforeach; ?> </ul> <p>Please correct the errors and re-submit this form.</p> </div> <? endif; ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input type="hidden" name="act" value="post"> <div class="buttonrow"> <input type="submit" value="Submit This Form " class="button" /> <a href="<?= $_SERVER['PHP_SELF'] ?>" >Start Again</a> </div> <p class="legend"><strong>Note:</strong> Required fields are marked with an asterisk (<em>*</em>)</p> <fieldset> <legend>User Details</legend> <div> <label for="uname" >User Name <em>*</em></label> <? if (isset($errMsgs['uname'])) echo 'class = "errors"' ?> <input id="uname" type="text" name="uname" value="<?=$_POST['uname'] ?>" /> (must be greater than 5 chars)</div> <div> <label for="email">Email Address </label> <input id="email" type="text" name="email" value="" /> </div> </fieldset> <fieldset> <legend>Submission</legend> <div> <label for="year">Year (YYYY) <em>*</em></label> <input id="year" type="text" name="year" <? if (isset($errMsgs['year'])) echo 'class = "errors"' ?> value="" size="4" maxlength="4" /> (4 digit number)</div> <div> <label for="date">Month (MM)</label> <input id="date" type="text" name="month" value="" size="4" maxlength="2" /> (number ranging from 1-12)</div> </fieldset> <fieldset> <legend>Preferences</legend> <div> <label for="type" >Province (Multiple Select) <em>*</em></label> <select name = "province[]" multiple size = "12" id="type" > <? foreach ($PROVINCES as $abbreviation => $longname); ?> <option value = "<?=$abbreviation ?> "></option> <? enfgoreach; ?> </select> </div> <div class= 'controlset' > <span class="label">Status (Mult Select)<em>*</em></span> <input name="status[]" id="approved" value="approved" type="checkbox" /> <label for="approved">Approved</label> <input name="status[]" id="pending" value="pending" type="checkbox" /> <label for="pending">Pending Application</label> <input name="status[]" id="actives" value="actives" type="checkbox" /> <label for="actives">Active Service</label> </div> <div class= 'controlset'> <span class="label"> Location <em>*</em></span> <input name="location" id="radio1" value="Garage" type="radio" /> <label for="radio1">Garage</label> <input name="location" id="radio2" value="Attic" type="radio" /> <label for="radio2">Attic</label> <input name="location" id="radio3" value="House" type="radio" /> <label for="radio3">House</label> </div> </fieldset> </form> <p>This debug info is here to help you. You are only required to display the POST array</p> <pre><?= print_r($_POST,true) ?> </pre> </div> </div> </body> </html> Hi, I am creating a cms using php and my sql for my website. I have managed to create the majority of it but am having trouble added a menu on each page. It appears on the homepage with the following code: <ul id="headlines"> <?php foreach ( $results['articles'] as $article ) { ?> <li> <h2> <a href=".?action=viewArticle&articleId=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a> </h2> </li> <?php } ?> </ul> Once I click on a selection from the menu it takes me to the correct article but there is no menu now. If I try to copy and paste the code from homepage into my viewArticle file it gives me the error messages 'undefined index articles on line 6' and 'invalid argument supplied for for each'. This is the viewArticle code after I pasted in the code from homepage: <ul id="headlines"> <?php foreach ( $results['articles'] as $article ) { ?> <li> <h2> <a href=".?action=viewArticle&articleId=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a> </h2> </li> <?php } ?> </ul> <h1 style="width: 75%;"><?php echo htmlspecialchars( $results['article']->title )?></h1> <div style="width: 75%;"><?php echo $results['article']->content?></div> I would really appreciate anybody helping me figure out how I can add the menu onto the viewArticle page. Thanks in advance hello , i have this code: <?php function error_table($err){ echo"<p><span class='textborder'>$err</span></p>"; } ?> in a separate php file and then call it from another php file , like this : $msg_err='bla bla'; error_table($msg_err); when i click the button it shows the text with its border(the class has a border ,color and 1px) but when i have the code inside other if functions it shows it 2 or 3 times... Hello, I have those code: $message = " Hello $inforow2['company']<br /> This is a notice about a pending invoice at $inforow3['company'].<br /> If you would like to see the invoice, you can see it <a href='http://$inforow3['url]'/view-invoice?id=$id.php'>here</a><br /> This is an automatic message. Replies will not be monitored.<br /> Yours faithfully<br />$inforow3['company']"; mail($inforow2['email'],"Invoice overdue #1",$message,$inforow3['sentfrom']); I'm not sure if I can send this, and it will get the values from my mysql and put it in the email or it would send the text directly, and if it ill take the html.. Can any one tell me if above code would be correct? Hi People,
I'm using a php to send an mail using a server via ssl. My program:
<?php I'm trying to send email with php for the first time. Trying to make it so that after a user registers he/she receives an email after submitting. I'm trying to send it from 1 comp with an email of goldie@telkomsa.net to another with an email of jgoldie@telkomsa.net (I just really want to test if it's sending email another before I get technical with the email) Should this code work, here is part of my code with the email section in it: Code: [Select] <?php // query $sql = "INSERT INTO student (sno, sname, init, fname, title, msname, dob, sex, lang, idno, telh, telw, cel, fax, email, address, contact_flag ) VALUES ('', '$sname', '$init', '$fname', '$title', '$msname', '$dob', '$sex','$lang', '$idno', '$telh', '$telw', '$$cell', '$fax', '$email', '$address', '$contact')"; mysql_query($sql) or die('Error:' . mysql_error()); $sno_id = mysql_insert_id(); // get the cid $cname = mysql_real_escape_string($_POST['cname']); $getCID = "SELECT cid FROM course WHERE cname='$cname'"; $result = mysql_query($getCID); if($result) { $row = mysql_fetch_assoc($result); $course_id = $row['cid']; // add the student to the course_student table $addCID = 'INSERT INTO course_student (cid, sno) VALUES(' . $row['cid'] . ', ' . $sno_id . ')'; mysql_query($addCID) or die('Error:' . mysql_error()); // send email $Name = "Da Duder"; //senders name $email = "goldie@telkomsa.net"; //senders e-mail adress $recipient = "jgoldie@telkomsa.net"; //recipient $mail_body = "The text for the mail..."; //mail body $subject = "Subject for reviever"; //subject $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields ini_set('sendmail_from', 'goldie@telkomsa.net'); //Suggested by "Some Guy" if (mail($recipient, $subject, $mail_body, $header)){ echo "mail has been sent"; //mail command } } header( "refresh:5;student_man.php" ); echo 'Registration <b> successful </b> You\'ll be redirected in about 5 secs. If not, click <a href="student_man.php">here</a>.'; } } ?> Email is under the "email section" comment based of what I found on google. I'm not getting any errors so I want to know if the email isn't going through because of my code or my smtp setting etc. Hello, I have been using the mail() command for a while now, but for some reason It has just stopped functioning all together. I have added an OR DIE rule to the end of it and had no response. To all intents and purposes that mail is being sent - there are no errors whatsoever - just the mail is not getting delivered. I cannot think of anything I've done or changed that would stop it from being delivered, I haven't even been near the function that does it in a while. Here is the code: Code: [Select] function sendMail($to,$ref) { $subject = 'Booking Confirmation'; $file = "receipts/$ref.htm"; $fh=fopen($file, "r"); $message = fread($fh, filesize($file)); fclose($fh); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: Company <noreply@company.co.uk>' . "\r\n"; mail($to, $subject, $message, $headers); } I have taken out the public names involved, but otherwise thats the code. It has worked absolutely fine in the past, and even If I strip out all of the filehandling part of it, and just use a simple $from - $to - $message, it still seems not actually send the mail. It wouldnt be so bad If I at least had an error to go on, but I dont I am just simply not getting the mail. Please help! ~Chud37 I understand you need to use the mail() command but this just wont work for me, my webserver is with godaddy, and they sent me an email saying that i need to use a relay server to send my mail, how do i set this up or anything? Can somebody tell me how to make this exact code send mail? I tested it on my website and it doesn't send any emails. The first code is the file contact_config.php <?php $mailto = "youremail@email.com"; $charset = "windows-1251"; $subject = "Site visitor: ".$_POST['posName']; $content = "text/html"; $message = "Site visitor information: <br><br> Name: ".$_POST['posName'] ."<br>E-mail: ".$_POST['posEmail'] ."<br>Country: ".$_POST['posCountry'] ."<br>Phone: ".$_POST['posRegard'] ."<br>Comments: ".$_POST['posText']; $statusError = ""; $statusSuccess = ""; $errors_name = 'Please enter the Name'; $errors_mailfrom = 'Please enter the Email'; $errors_incorrect = 'The e-mail address you entered does not eppear to be valid. <br>Your e-mail address should look like yourname@domain.com'; $errors_message = 'Please enter the Message'; $errors_subject = 'Please enter the Phone'; $captcha_error = 'Wrong security code!'; $send = 'Thank you for your message'; ?> <?php $mailto = "youremail@email.com"; $charset = "windows-1251"; $subject = "Site visitor: ".$_POST['posName']; $content = "text/html"; $message = "Site visitor information: <br><br> First Name: ".$_POST['posName'] ."<br>Last Name: ".$_POST['posName2'] ."<br>E-mail: ".$_POST['posEmail'] ."<br>Telephone: ".$_POST['posRegard'] ."<br>City where jobsite is located: ".$_POST['posText'] ."<br>want us to e-mail you the free Homeowners Guide To Remodeling: ".$_POST['posBox']; $statusError = ""; $statusSuccess = ""; $errors_name = 'Please enter the First Name'; $errors_name2 = 'Please enter the Last Name'; $errors_telephone = 'Please enter the Telephone'; $errors_city = 'Please enter the City where jobsite is located'; $errors_mailfrom = 'Please enter the Email'; $errors_incorrect = 'The e-mail address you entered does not eppear to be valid. <br>Your e-mail address should look like yourname@domain.com'; $captcha_error = 'Wrong security code!'; $send = 'Thank you for your message'; ?> The second code is contacts.php <?php include('kcaptcha/kcaptcha.php'); session_start(); require_once("contact_config.php"); if ($_POST['act']== "y") { if(isset($_SESSION['captcha_keystring']) && $_SESSION['captcha_keystring'] == $_POST['keystring']) { if (isset($_POST['posName']) && $_POST['posName'] == "") { $statusError = "$errors_name"; } elseif (isset($_POST['posEmail']) && $_POST['posEmail'] == "") { $statusError = "$errors_mailfrom"; } elseif(isset($_POST['posEmail']) && !preg_match("/^([a-z,._,0-9])+@([a-z,._,0-9])+(.([a-z])+)+$/", $_POST['posEmail'])) { $statusError = "$errors_incorrect"; unset($_POST['posEmail']); } elseif (isset($_POST['posText']) && $_POST['posText'] == "") { $statusError = "$errors_message"; } elseif (!empty($_POST)) { $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: $content charset=$charset\r\n"; $headers .= "Date: ".date("Y-m-d (H:i:s)",time())."\r\n"; $headers .= "From: \"".$_POST['posName']; $headers .= "X-Mailer: My Send E-mail\r\n"; mail("$mailto","$subject","$message","$headers"); $_POST['posRegard'] = ""; $_POST['posText'] = ""; $_POST['posCountry'] = ""; $_POST['posEmail'] = ""; $_POST['posName'] = ""; unset($name, $posText, $mailto, $subject, $posRegard, $message); $statusSuccess = "$send"; } }else{ $statusError = "$captcha_error"; unset($_SESSION['captcha_keystring']); } } $cat_name="Contact $store_name manager"; ?> Now for some reason the two of these files are supposed to send me emails when customers click the submit email button on my form but, I don't get any emails. I tested it myself and no emails. Help please! I wanna give error messages if the user dont enter their name, email or comments. I trıed to do it but mine didnt work. Please help me do it. Index.php page Code: [Select] <html> <head> <title>Guestbook</title> </head> <body> <font color="#CC0000" size="+2">Please sign our guestbook</font> <br \> <br \> <?php echo "<form name=\"Guestbook\" action=\"confirm.php\" method=\"post\">\n"; echo "<table bgcolor=\"#DAE5CD\">\n"; echo " <tr>\n"; echo " <td valign=\"top\">Name: </td>\n"; echo " <td><input type=\"text\" name=\"name\" size=\"25\" value=\"Your Name\"></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td valign=\"top\">E-mail:</td>\n"; echo " <td><input type=\"text\" name=\"email\" size=\"25\" value=\"example@mail.com\"></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td valign=\"top\">Comments:</td>\n"; echo " <td><textarea rows=\"5\" cols=\"30\" name=\"comments\">Comments</textarea></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td></td>\n"; echo " <td align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Submit\"> <input type=\"reset\" value=\"Clear\"> </td>\n"; echo " </tr>\n"; echo "</table>\n"; echo "</form> "; ?> </body> </html> confirm.php page Code: [Select] <html> <head> <title> Submission receieved! </title> </head> <body> <font size="+2" color="#00B0EB">Your submission has been sent successfully!</font><br /> <br /> <?php //extract($_REQUEST); if (!isset($_POST["$submit"])) { if (empty($_POST["name"])) { echo "Please enter your name!"; } else if (empty($_POST["email"])) { echo "Please enter your E-mail"; } else if (empty($_POST["comments"])) { echo "Please enter some text"; } } ?> <table bgcolor="#DAE5CD" width="%50" cellpadding="5"> <tr> <td valign="top" width="75">Name : </td> <td> <?php echo $_POST["name"];?> </td> </tr> <tr> <td valign="top">E-Mail : </td> <td> <?php echo $_POST["email"]; ?> </td> </tr> <tr> <td valign="top">Comments :</td> <td> <?php echo $_POST["comments"]; ?> </td> </tr> </table> </body> </html> I have a process that runs in the background, so I don't get to see its output. What I would like to do, is if a error occurs (mysql or php) send me an email with the error message(s), then end the process. Any way I can do this? Right now, I am not sure if any errors occur, but I am thinking that they might be happening. So any way for me to get the error would be awesome! |