PHP - Help With An Email Script
Alright, so here's the problem. I am trying to code up a PHP script that basically sends an email. Sounds basic, right? Here's the tricky part.
Using HTML or any other code will simply just load your default mail client and try to send it with that, what I need is a script that sends it via my website. I'll try to explain, Name: (This will send me their name they type) Email: (Same as above) Submit: (This will be the button they press when they submit the fore-mentioned details.) What would need to happen is the PHP would need to include the data entered in the name, and email field, (after the user clicks the submit button) copy it, and paste it into a email that is sent to my email address. (My email needs to be hidden obviously) But this needs to be done server side, without opening the person's mail client. And then once the email is sent, they need to be re-directed to a page. Only problem is, I CANNOT code PHP to save my life, I know this script is possible I've had it done before but lost the script Much appreciated anyone who can help me out on this one! Similar TutorialsHi, n0obie here. I'm trying to identify where my customers are coming from via emails I've sent/received. However, many email providers (namely Gmail) have circumvented this by disallowing IP address geolocation/image caching. Code: [Select] $sql="SELECT * FROM $tbl_name3 WHERE review_show='n'"; $result=mysql_query($sql); $num_results=mysql_num_rows($result); if($num_results > 1){ $message="You have ".$num_results." reviews unapproved."; mail('example@example.com','GHP Reviews', $message, 'From: example@example.com'); } $sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'"; $result2=mysql_query($sql2); $num_results2=mysql_num_rows($result2); if($num_results2 > 1){ $message="You have ".$num_results2." RMA Numbers Requested."; mail('example@example.com','GHP RMA Number Requests', $message, 'From: example@example.com'); } The reviews email is being sent, however, the RMA email is not. EDIT: Nevermind, $num_results and $num_results2 should have been > 0 not > 1. Hi Everyone! Thanks in advance for taking the time to review my post. I am pretty new to PHP so please excuse my ignorance. I am working a project for myself. I want to be able to send out newsletters to my customers and sponsors. I have written the code and here it is: <?php $subject = $_POST['subject']; $message = $_POST['message']; $email = "bubba@bubba.com"; $headers = "From: $email"; $email_list = file("elist.txt"); $total_emails = count($email_list); for ($counter=0; $counter<$total_emails; $counter++) { $email_list[$counter] = trim($email_list[$counter]); } $to = implode(",",$email_list); if ( mail($to,$subject,$message,$headers) ) { echo "The email has been sent!"; } else { echo "The email has failed!"; } ?> ----------------------------------------------------------------------------- In my elist.txt file - I have two fields. Name and email. Bubba|bubba@bubba.com Oohay|oohay@yahoo.com If i leave the names out of this file, the email script works great! I want to leave the names in there and reference them in my email that I am sending out to be more personal. Can this be done and can you help? Thanks! Mike I am experiencing compleate brain failure here please help if you can. This is my email script, how do i include multiple input, into the $body tag? example: vieweremail + comments + phonenumber + alot other stuff?? As of now i can only make it include 1 user input field thats is 'vieweremail'. <?php $to = $_POST['email_addy']; $subject = " your dating app"; $body = $_POST['vieweremail']; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> Hi Everyone, I read a few things before having posted this. I think I am in the right place; but as a caveat, please correct me if I am in the wrong place. At any rate, I am a designer who is just learning to code in php. I am studying on my own, now. This is only my second post here, and I don't know what I am doing. I have never written an email script before and very little of what I have seen makes sense to me, as yet. I would like to: 1.) have the "Is this urgent?" checkbox checked if the user selects either: a.) I am a Journalist b.) Received wrong order c.) Order not received d.) Credit Card Issue 2.) Send this email The code is below. Code: [Select] <div id="form"> <form id="contact" method="post" action="contactForm.php"> <div class="fields"> <fieldset> <!--this is the name field--> <label for="name"><span>Name</span> <input type="text" name="name" id="name" /> </label> <!--end of the name field--> <!--this is the email field--> <label for="email"><span>Email</span> <input type="text" name="email" id="email" /> </label> <!--end of the email field--> <!--this is the telephone field--> <label for="telephone"><span>Telephone</span> <input type="text" name="telephone" id="telephone" /> </label> <!--end of the telephone field--> </fieldset> </div> <fieldset> <!--this is the reason menu--> <label for="reasonMenu"><span>Reason for contact</span> <select id="reasonMenu"> <option selected="selected" value="choose">Please Choose</option> <option value="general">General Inquiry</option> <option value="designer">I am a Journalist</option> <option value="corporate">Corporate Gifts</option> <option value="item">Item Request</option> <option value="designer">I am a Designer</option> <option value="supplier">I am a Supplier Rep</option> <option value="vip">VIP Candi Ladies</option> <option value="orderNot">Order Not Received</option> <option value="orderWrong">Received Wrong Order</option> <option value="credit">Credit Card Issue</option> </select> </label> <!--end of the reason menu--> <!--this is the item number field--> <label for="item"><span>Item Number?</span> <input type="text" name="item" id="item" /> </label> <!--end of the item number field--> </fieldset> <fieldset> <!--this is the message box--> <label for="message"><span>Message</span> <textarea name="message" rows="10" cols="25" id="message"> Please type your message here. </textarea> </label> <!--end of the message box--> <!--this is the urgent checkbox--> <!--<div id="checkbox">--> <span id="urgent">Is This Urgent?</span> <label for="checkbox" id="checkbox"> <input type="checkbox" name="checkbox" value="URGENT!" id="checkbox" /> </label> <!--</div>--> <!--end of the urgent checkbox--> </fieldset> <!--this is the submit button--> <div id="sendBtn"> <input type="submit" value="Send This Form" /> </div> <!--end of the submit button--> <!--this is the reset button--> <div id="clearBtn"> <input type="reset" value="Clear The Form" /> </div> <!--end of the reset button--> <!--end of the message box--> </form> Thank you all in advance for your help. Hi guys, I am writing the php script to send the email. I have noticed when I picked up on my email, I can see that it have been covered with mailed-by: myservername.com. I want to hide it, but I can't find a way to get it resolve. Here's the code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $name = clean($_GET['name']); $email = clean($_GET['email']); $type = clean($_GET['type']); $comments = clean($_GET['comments']); if($name == ''){ $errmsg_arr[] = 'name are missing.'; $errflag = true; } elseif($email == ''){ $errmsg_arr[] = 'email are missing.'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['name'])) { $insert[] = 'name = \'' . clean($_GET['name']) .'\''; } if(isset($_GET['email'])) { $insert[] = 'email = \'' . clean($_GET['email']) . '\''; } if(isset($_GET['type'])) { $insert[] = 'type = \'' . clean($_GET['type']) . '\''; } if(isset($_GET['comments'])) { $insert[] = 'comments = \'' . clean($_GET['comments']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if(isset($email)){ $name = $_GET['name']; $email = $_GET['email']; $header = "From: $name <$email>". "\r\n"; $to = "myname@myemail.com"; $subject = $type; $message = "$comments & $rate"; $header .= "MIME-Version: 1.0\l\n"; $add = "<$email>"; mail($to, $subject, $message, $header, $add); echo "Thank you for sent us your email"; } } } ?> I guess that something got to do with this: if(isset($email)){ $header = "From: $name <$email>". "\r\n"; $header .= "MIME-Version: 1.0\l\n"; $add = "<$email>"; } I have disabled the safe-mode, so do you know how I can hide the mailed-by header using with the code on above?? Any advice would be much appreciate. Thanks in advance. I've sent test to server and verified that email working. New with PHP so assuming my code is wrong.
Attached Files
contact.html 22.48KB
0 downloads
contact_script.php 3.5KB
3 downloads Iwant to make a contact us script and here is done so far. I am almost sure its about preg match filters but cant find a solution why it doesnt work. Appreciate any help. Here is my code: $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_from = $_POST['email']; $comments = $_POST['comments']; $emailtrue = '/^([A-Za-z0-9-_]+@[A-Za-z0-9-_]+\.[A-Za-z]{2,4})$/'; $nametrue = "/^[A-Za-z]+$/D"; if(!preg_match($nametrue,$first_name)) { echo "The First Name you entered does not appear to be valid."; die (); } if(!preg_match($nametrue,$last_name)) { echo "The Last Name you entered does not appear to be valid."; die (); } if(!preg_match($emailtrue,$email_from)) { echo "The Email Address you entered does not appear to be valid."; die (); } if(strlen($comments) < 4) { echo "The Comments you entered do not appear to be valid. Min. 4 letters." ; die (); } $to = xxxxxxxxxx.com'; $subject = 'User Email'; $headers = 'From: '.$email_from. "\r\n" . 'Reply-To: '.$email_from. "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $comments, $headers); Trying to use an include() in a script to send an email, not working out. Basically I have a pretty drastic page I've formatted out and I want it to be shipped out in an email in that format. I thought it would be simple to get an include in a php code to email but the email works.. and doesn't have anything in it. I've tried with and without quotes, any help appreciated. Code: [Select] <html> <body> <? //change this to your email. $to = "me@me.com"; $from = "me@me.com"; $subject = "stuff"; $message="<?php include("another.php"); ?>" $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; //options to send to cc+bcc //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]"; //$headers .= "Bcc: [email]email@maaking.cXom[/email]"; // now lets send the email. mail($to, $subject, $message, $headers); echo "Message has been sent....!"; ?> </html> </body> Hi Guys I'm just looking for some advice to make sure i go in the right direction from the off! Building a new system for a client. They'll receive contact information from a contact form on their website and the details of the contact form are logged in the admin area of the cms. The client wants to be able to respond to these contacts via email without logging into the system and then have the details of the reply logged in the admin area of the cms to know when something has been responded to. So essentially i need some way of getting that email into the database. The only way i can see this happening is to setup a new mailbox, the client blind copies that mailbox address into all replies, a cron then runs a php script that picks up most recent emails via imap and then reads in the data - thereby registering the fact a response has happened (probably from the subject line reference) and it would then update the status of the contact. I am assuming this is theoretically possible as i've never done anything like that before. So... 1) Is there a better way of doing this without having the client login to the site to respond? 2) Does the proposal above sound reasonable? Any advice would be much appreciated... Drongo Can someone show me a simple mail script that I can run in cli, I can enter a $to = email@email.com and then have it send to my email? just in cli.. Thanks Guys Im having a strange issue with my code I have a form to request a password to be sent to email incase forgotten The script seems to run as it should as in taking the info then redirecting to the messages page for confirmation no problem but its not sending the email Ive checked and double checked, and even re written the code from scratch and nothing seems to be playing ball in sending the email Can someone shed some none sleep deprived eyes over it and point out what will no doubt be an obvious error I just cant seem to see The Form: Code: [Select] <form name="sendpw" method="post" action="sendpw.php"> <br> <table width="100%" border="0" class="tbl"> <tr> <td width="198"><div align="right">Username:</div></td> <td width="418"><input name="name" type="text" class="input" size="30"></td> </tr> <tr> <td><div align="right">Email: </div> </td> <td><input name="mail" type="text" class="input" size="30"></td> </tr> <tr> <td colspan="2"> <div align="center"> <input name="Submit" type="submit"> </div></td> </tr> </table> </form> The Script: Code: [Select] <? include ('config.php'); $name=$_POST['name']; $em=$_POST['mail']; $query="SELECT pw FROM user WHERE uname='$name' AND email='$em'" or die (mysql_error()); $result= mysql_query($query); $row = mysql_fetch_assoc($result); $pass=$row['pw']; $to="$em"; $from="From: passwords@MBD.net"; $msg="Username: $name\r\n"; $msg .="Password: $pass\r\n"; $msg .="Please keep this password safe"; $subject="Your Login Password\r\n"; mail($to,$subject,$msg,$from); header( "Location:messages.php?msg=2" ); exit(); ?> config.php is just my database connection info, which is working fine as it runs all all my pages that access the database. Thanks Tom I am working on an email extractor script that will extract emails from a site. I have a working script that will extract them from a single URL, but what I need it to do is to follow the links on the page. Here is my email script: <?php $the_url = isset($_REQUEST['url']) ? htmlspecialchars($_REQUEST['url']) : ''; ?> <form method="post"> Please enter full URL of the page to parse (including http://):<br /> <input type="text" name="url" size="65" value="http://<?php echo str_replace('http://', '', $the_url); ?>"/><br /> or enter text directly into textarea below:<br /> <textarea name="text" cols="50" rows="15"></textarea> <br /> <input type="submit" value="Parse Emails" /> </form> <?php if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) { // fetch data from specified url $text = file_get_contents($_REQUEST['url']); } elseif (isset($_REQUEST['text']) && !empty($_REQUEST['text'])) { // get text from text area $text = $_REQUEST['text']; } // parse emails if (!empty($text)) { $res = preg_match_all( "/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", $text, $matches ); if ($res) { foreach(array_unique($matches[0]) as $email) { echo $email . "<br />"; } } else { echo "No emails found."; } } ?> <!-- Email Extractor END --> It's a bit rough and quirky, but it works for a single URL. Here is the email extractor in action: http://www.site-search.org/email-extractor.php My ideal solution would be to combine this script with my URL extactor/link-extractor script: <!-- URL Extractor BEGIN --> <?php // findlinks.php // php code example: find links in an html page // mallsop.com 2006 gpl echo "<form method=post action=\"$PHP_SELF\"> \n"; echo "<p><table align=\"absmiddle\" width=\"100%\" bgcolor=\"#cccccc\" name=\"tablesiteopen\" border=\"0\">\n"; echo "<tr><td align=left>"; if ($_POST["FindLinks"]) { $urlname = trim($_POST["urlname"]); if ($urlname == "") { echo "Please enter a URL. <br>\n"; } else { // open the html page and parse it $page_title = "n/a"; $links[0] = "n/a"; //$meta_descr = "n/a"; //$meta_keywd = "n/a"; if ($handle = @fopen($urlname, "r")) { // must be able to read it $content = ""; while (!feof($handle)) { $part = fread($handle, 1024); $content .= $part; // if (eregi("</head>", $part)) break; } fclose($handle); $lines = preg_split("/\r?\n|\r/", $content); // turn the content into rows // boolean $is_title = false; //$is_descr = false; //$is_keywd = false; $is_href = false; $index = 0; //$close_tag = ($xhtml) ? " />" : ">"; // new in ver. 1.01 foreach ($lines as $val) { if (eregi("<title>(.*)</title>", $val, $title)) { $page_title = $title[1]; $is_title = true; } if (eregi("<a href=(.*)</a>", $val, $alink)) { $newurl = $alink[1]; $newurl = eregi_replace(' target="_blank"', "", $newurl); $newurl = eregi_replace(' rel="nofollow"', "", $newurl); $newurl = eregi_replace(" title=\"(.*)\"","", $newurl); $newurl = trim($newurl); $pos1 = strpos($newurl, "/>"); if ($pos1 !== false) { $newurl = substr($newurl, 1, $pos1); } $pos2 = strpos($newurl, ">"); if ($pos2 !== false) { $newurl = substr($newurl, 1, $pos2); } $newurl = eregi_replace("\"", "", $newurl); $newurl = eregi_replace(">", "", $newurl); //if (!eregi("http", $newurl)) { // local // $newurl = "http://".$_SERVER["HTTP_HOST"]."/".$newurl; // } if (!eregi("http", $newurl)) { // local $pos1 = strpos($newurl, "/"); if ($pos1 == 0) { $newurl = substr($newurl, 1); } $newurl = $urlname."/".$newurl; } // put in array of found links $links[$index] = $newurl; $index++; $is_href = true; } } // foreach lines done echo "<h2>Extracted Links</h2>\n"; echo "<p><b>Page Summary</b><br>\n"; echo "<b>Url:</b> ".$urlname."<br>\n"; if ($is_title) { echo "<b>Title:</b> ".$page_title."<br>\n"; } else { echo "No title found<br>\n"; } echo "<b>Links:</b><br>\n"; if ($is_href) { foreach ($links as $myval) { echo "<a href=\"$myval\">".$myval."</a><br>\n"; } } else { echo "No links found<br>\n"; } echo "End</p>\n"; } // fopen handle ok else { echo "<br>The url $urlname does not exist or there was an fopen error.<br>"; } echo "<br /><br /><h4><a href=\"http://www.site-search.org/url-extractor.php\" title=\"Link Extractor\">Try Again</a></h4>"; } // end else urlname given } // else find links now submit else { $urlname = ""; // or whatever page you like echo "<br /><br />\n"; echo "<p><h2>Link Extractor</h2><br>\n"; echo "File or URL: <input type=\"TEXT\" name=\"urlname\" value=\"http://\" maxlength=\"255\" size=\"80\">\n"; echo "<input type=\"SUBMIT\" name=\"FindLinks\" value=\"Extract Links\"></font><br></p> \n"; echo "<br /><br />\n"; } echo "</td></tr>"; echo "</table></p>"; echo "</form></BODY></HTML>\n"; ?> <!-- URL Extractor END --> Her e is the script in action: http://www.site-search.org/url-extractor.php Hello, I am new to PHP and would like to know what I am doing incorrectly. I have designed a login form which contains two variables: the username and the password. So for the username: <input type="hidden" name="email" id="email" value="example_username"> And for the password: <input type="password" name="password" id="password" size="15"> I then created a php script which I want to pass the variables "email" and "password" to the e-mail address: <?php { $message = "$email"; $message2 = "$password"; mail ("email@myserver.com", "Hello", $message, $message2); } ?> This should happen through the command: <action="http://www.myserver.com/myscript.php" method="post"> All I get is a blank email with the subject "Hello". Why are the email and password variables not being passed to my email by the php script? Thanks. This is completely different code than my change password script thread. This is not double posting. Whenever I use this script to change my email, it just changes the email to nothing (blank). What could be wrong with it? Help is hugely appreciated. I know you don't have to use your valuable time to help me. <?php // I removed the connect to db part session_start(); $username = $_SESSION['username']; $email = $_POST['email']; $newemail = $_POST['newemail']; $confirmnewemail = $_POST['confirmnewemail']; $result = mysql_query("SELECT email FROM members WHERE username='$username'"); if($email!= mysql_result($result, 0)) { echo "The email address you entered is incorrect."; } if($newemail==$confirmnewemail) $sql=mysql_query("UPDATE members SET email='$newemail' where username='$username'"); if($sql) { echo "You have successfully changed your email address."; } else { echo "The new email and confirm new email fields were different."; } ?> Hi everybody, I want to create a script which will send SMS on a number once new mail arrives in email account. I have SMS API service from http://www.freesmsapi.com/ I am using cPanel, but how to do it ? One idea is, new mails are stored in "new" folder and already read mails are stores in "cur". So once, new email file will come in "new" folder PHP script will see that file and will send SMS, with text as "Hi, {user}, you gotta mail from {sender}, subject is {sibject}" That PHP file will be added to Cronjobs. But how to do it ? I have been searching on this issue from many months, did google but no answer. I need help Hi,
I have a section of code that sends an order confirmation to me when a customer places an order with us.
This all works fine but recently, I have started to get duplicate confirmations coming from the same customers, one in particular, many times a day...
Is there anything obvious about this code that could be causing it?
Thanks,
<?php I am using a simple email script called PHPmailer which works great but i would like to create a form so a user can input what the text for the email should be along with the subject from texts boxes, i also need the script to connect to a mysql database to get a list of email address to send to. Then once the user presses the send button the email is sent out to everyone in the database. Can anyone help me? <?php include_once('class.phpmailer.php'); $mail = new PHPMailer(); $body = eregi_replace("[\]",'',$body); $mail->IsSendmail(); // telling the class to use SendMail transport $mail->From = "zac@zpwebsites.com"; $mail->FromName = "First Last"; $mail->Subject = "PHPMailer Test Subject via smtp"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $mail->AddAddress("zacthespack@gmail.com", "John Doe"); $mail->AddAttachment("uploads/AleMail.pdf"); // attachment if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> Ok, I submit the form, and when the next page displays, it says recieved with the persons name, but it wont post their email, and it wont ever send the message to the email address......... i've been playing with it all day long and just cannot figure it out, about to rip my hair out... any help would be appreciated. Contact.php page Code: [Select] <?php // Header Include include('includes/header.php'); ?> <!-- BEGIN SITE CONTENT INCLUDES HERE --> <!-- Index page included --> <table border="0" cellpadding="5" cellspacing="0" width="300" align="center"> <tr> <td><font face="verdana" size="2" color=#"000000"><b>Feedback Form</b></font></td> <tr> <td><form name="contact" method="post" action="contact_submit.php"> <font face="verdana" size="1" color="#1b4a1b">Your Name:<br /> <input type="text" name="name" size="25" /> <br /> Email:<br /> <input type="text" name"email" size="25" /> <br /> Comments:</font><br /> <textarea name="comments" rows="5" cols="30"></textarea> <br /><input type="submit" name="submit" value="Send" /> </form></td> </tr> </table> <br /><br /> <!-- / End Index Page --> <!-- / END SITE CONTENT INCLUDES HERE --> <!-- Footer Include --> <?php include('includes/footer.php'); ?> Form Processing Script contact_submit.php Code: [Select] <?php $to = "tonyagmatrix@gmail.com"; $re = "Feedback Form"; $msg = $comments; mail($to,$re,$msg); ?> <html><head><title>Message Recieved</title></head> <body> <h3>Thank you for your feedback <?PHP echo ($name); ?></h3> <br />We value your opinions and any questions will be replyed to your email address: <?php echo ($email); ?> </body></html> Does anyone have any idea wtf is wrong? |