PHP - Php Mail Problem
I have a basic mail script (with the standard mail function: mal() ) that I use for a confirmation email (in a users sign up form). The form and the mail is almost always successfully submitted. Although every once in a while, I get the following error :
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() BTW, the users input is succesfully inserted into the database; but he never recieves the confirmation mail.... Similar TutorialsHello to all out there! this is my first post,so my question may sound a bit simple. :] I am studying PHP and MySQL and I tried to make a mailing form based on a mysql database. My problem occured when I tried to use the PEAR mail object. Here is my code: // THE INCLUDED FILES require_once ("attach_file.php" ); require_once ("Mail.php" ); require_once ("Mail\mime.php" ); //THE VARIABLES TAKEN FROM THE HTML FORM OR JUST CREATED FOR THE CONSTRUCTION OF THE EMAIL $my_email = "something@gmail.com"; $email_subject = mysql_real_escape_string(trim( $_POST['email_subject']),$server_connect ); $email_body = mysql_real_escape_string(trim( $_POST['email_body'] ),$server_connect ); $attached_file = $destination ; // the $destination variable comes from the copy() function in attach_file.php $username = "the_username@gmail.com"; $password = "the_password"; $host = "smtp.gmail.com"; $attach = new Mail_mime(); $attach -> addAttachment($attached_file); $email_body = $attach->get(); $extraheaders = array('from'=>$my_email,'to'=>$email_etaireias,'subject'=>$email_subject,'Bcc'=>$email_etaireias); $headers = $attach -> $headers($extraheaders); // HERE GIVES ME AN ERROR!!! -->Fatal error: Method name must be a string $smtp_info = array('host'=>$host,'auth'=>TRUE,'username'=>$username,'password'=>$password); $smtp = Mail::factory('smtp',$smtp_info); //loop through every single line of the database until there are no more lines with data //and store each line in 3 different variables that i can use while ( $row = mysql_fetch_array($result) ) { $onoma_etaireias = $row['onoma_etaireias']; $email_etaireias = $row['email_etaireias']; $website_etaireias = $row['website_etaireias']; } //construct the mail function . The @ is supressing the errors created .remove it and they will be shown. $mail = @$smtp->send($email_etaireias,$headers,$email_body); As i searched here and there for a solution, i found that it has something to do with the way the mail-mime object creates the body of the email . I also tried to find a solution from the PEAR documentation. do i create the headers someway wrong????? I have a notification system that notifies users of new comments, inside the email I have images, some of the logo, some of different people, everything shows up fine on my computer (yahoo email), however in the iPhones email application no images show up, there are just the blue squares with the question marks in them. I'm not sure what I'm missing. Code: [Select] $from = "Kithell <notifications@kithell.com>"; $headers = "From:" . $from ."\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $subject = name($from_id, 'fl').$action; $message = '<html><body> <style>@charset "utf-8"; /* CSS Document */ .e-container { background-color: #FFF;position: relative;width: 90%;min-height:1px;margin-right: auto;margin-left: auto; } .e-container .e-m-header { padding: 2px; background-image: url(http://www.kithell.com/assets/tall-grey-header.png); background-repeat: repeat-x; border: 1px solid #CCC; background-position: bottom; display: block; text-align: center; } .e-container p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #666; vertical-align: text-top; display: inline-block; } .e-container .e-usr-photo { display: inline-block; margin: 10px; float: left; background-color: #F4F4F4; } .e-container p a { font-weight: bold; color: #3F60A3; text-decoration: underline; padding: 0px; float: left; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px; } .e-container .e-quotes { font-size: 20px; font-weight: bold; color: #999; font-family: Tahoma, Geneva, sans-serif; display: block; padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 75px; margin-top:10px; } .e-container .e-message { font-size: 13px; color: #333; padding: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 10px; clear: none; display: inline; }</style> <div class="e-container"><div class="e-m-header"><img src="http://www.kithell.com/assets/kithell-logo.png" /></div><img class="e-usr-photo" src="http://www.kithell.com/'.photo($from_id, 55).'" /><br /><p><a target="_blank" href="http://www.kithell.com/#/profile&id='.$from_id.'">'.name($from_id, "fl").' </a> '.$action.'<div class="e-quotes">"<p class="e-message">'.nl2br(htmlentities(stripslashes($message))).'</p>"</div></p></div></body></html>'; mail($to,$subject,$message,$headers); This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 Hello! Dear all, I'm having this problem with PHP Mail From Name, it took me entire day, and still haven't figure out the issue...that is... In "From: ", if I have it in simple email format, such as "From: name@server.com" it works...but when I have it with a From Name, eg. "From: Name <name@server.com>", then it just wouldn't send... I heard that some of the servers just won't parse "Name <name@server.com>", if it is the case...would there be any work around to get that From Name appeared? The code is attached below, any help is deeply appreciated! <?php //For Captcha include("settings.php"); header("Content-Type: text/html; charset=utf-8"); @session_start(); $string = strtoupper($_SESSION['string']); $userstring = strtoupper($_POST['userstring']); @session_destroy(); if (($string != $userstring) || (strlen($string) <= 4)) { header("location:contact_us.php"); exit(); } //PHP Mail starts here $form_name = $_POST["name"]; $form_company = $_POST["company"]; $form_email = $_POST["email"]; $form_phone = $_POST["phone"]; $form_mobile = $_POST["mobile"]; $form_msg = $_POST["msg"]; $form_date = date(Y)."-".date(m)."-".date(d); $form_ip = $_SERVER["REMOTE_ADDR"]; $form_lang = "en"; $fromname = "Name"; $frommail = "name@server.com"; @require("../default_timezone.php"); $con = mysql_connect("host","user","pass"); mysql_query("SET NAMES 'utf8'"); if (!$con) { die("Could not connect: " . mysql_error()); } mysql_select_db("dbname", $con); mysql_query("INSERT INTO tablename (CU_Name, CU_Company, CU_Email, CU_Tel, CU_Mobile, CU_Content, CU_CreateDate, CU_IP, lang) VALUES ('$form_name', '$form_company', '$form_email', '$form_phone', '$form_mobile', '$form_msg', '$form_date', '$form_ip', '$form_lang')"); $message = (" <table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"> <tr> <td colspan=\"2\" align=\"left\"><img src=\"contact_logo.gif\" /></td> </tr> <tr> <td colspan=\"2\" align=\"left\"><font style=\"font-size: 12px; color: #000;\">Your email is recceived, a representative will be contacting you soon.</font></td> </tr> <tr> <td width=\"70\" align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Name:</b></font></td> <td width=\"430\" align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_name}</font></td> </tr> <tr> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Company:</b></font></td> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_company}</font></td> </tr> <tr> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Email:</b></font></td> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_email}</font></td> </tr> <tr> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Phone:</b></font></td> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_phone}</font></td> </tr> <tr> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Mobile:</b></font></td> <td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_mobile}</font></td> </tr> <tr> <td align=\"left\" valign=\"top\"><font style=\"font-size: 12px; color: #000;\"><b>Message:</b></font></td> <td align=\"left\" valign=\"top\"><font style=\"font-size: 12px; color: #000;\">{$form_msg}</font></td> </tr> </table> "); $subject = "Email Subject"; $mime_boundary = md5(uniqid(mt_rand(), TRUE)); $header = "From: ".$fromname." <".$frommail.">\r\n"; $header.= "To: " . $to . "\r\n"; $header.= "MIME-Version: 1.0\r\n"; $header.= "Content-Type: multipart/mixed; \r\n"; $header.= " boundary=". $mime_boundary . "\r\n"; $content = "This is a multi-part message in MIME format.\r\n"; $content .= "--" . $mime_boundary . "\r\n"; $content .= "Content-Type: text/html; charset=utf-8\r\n"; $content .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; $content .= $message. "\r\n"; $to=$form_email; @mail($to, $subject, $content, $header); $to2="my@server.com"; @mail($to2, $subject, $content, $header); echo "<html>"; echo "<head>"; echo "<META HTTP-EQUIV='Content-Type' content='text/html; charset=utf-8'>"; echo "<META HTTP-EQUIV='Refresh' CONTENT='3; URL=http://www.server.com/'>"; echo "</head>"; echo "<body>"; echo "Thank you for contacting us!"; echo "<br />"; echo "Your message is sent."; echo "</body>"; echo "</html>"; ?> i'm running php 5.3 in wamp server with windows xp sp3 <?php $Name = "my name"; //senders name $email = "mymail@gmail.com"; //senders e-mail adress $recipient = "some_mail@hotmail.com"; //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', 'mymail@gmail.com'); //Suggested by "Some Guy" ini_set('SMTP', 'smtp.gmail.com'); //Suggested by "Some Guy" ini_set('smtp_port', 465); //Suggested by "Some Guy" $result = mail($recipient, $subject, $mail_body, $header); //mail command return $result; ?> some one help me please I am trying to get the PHP mail function to work. I am using a WAMP server and php.ini is set to: [mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. ;sendmail_from = ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ;sendmail_path = ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters = My PHP script looks like this: <php? $to = "djbouch@comcast.net"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "djbouch@comcast.net"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> For some reason the mail won't send and I am getting the following message: Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() Thanks for your help with this. Daniel I have this code in borrow.php Whenever they click the button 'sendMail' an email is sent to that user who tries to borrow that specific book (the book details are left out cuz we don't need them here) Code: [Select] <?php global $interface; global $user; if (isset($_POST['sendMail'])){ $to = $partner->email; $subject = "ILB Request"; if(!isset($user->id)){ $lastname = $_POST['lastname']; $firstname = $_POST['firstname']; $email = $_POST['email']; $telephone = $_POST['telephone']; $fax = $_POST['fax']; }else{ $lastname = $user->lastname; $firstname = $user->firstname; $email = $user->email; $telephone = $user->telephone; $fax = $user->fax; } $message = " <html> <body> <h2>Loaner Details</h2> <table> <tr> <td>Name: </td> <td>" . $lastname . "</td> </tr> <tr> <td>First Name: </td> <td>" . $firstname . "</td> </tr> <tr> <td>Email: </td> <td>" . $email . "</td> </tr> <tr> <td>Telephone: </td> <td>" . $telephone . "</td> </tr> <tr> <td>Fax: </td> <td>" . $fax . "</td> </tr> </table> </body> </html> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers if(!isset($user->id)){ $headers .= 'From: <' . $_POST['email'] . '>' . "\r\n"; }else{ $headers .= 'From: <' . $user->email . '>' . "\r\n"; } if(!empty($email)){ if(mail($to,$subject,$message,$headers)){ $interface->assign('success', "Your IBL request has been sent succesfully!"); }else{ $interface->assign('success', "Your IBL request has failed!"); } }else{ $interface->assign('success', "Email address has to be filled in!"); } } And then there is this code in Edit.php: Whenever a person changes someone elses profile (like an admin), the person whos profile is being changed needs to be notified by email. It's the same function as before though it gives this error: "Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\vufind\web\services\MyResearch\Edit.php on line 182" But the php.ini file hasn't been changed, and it doesn't give error the the previous code above (+ I receive the email) So I add to the file below: Code: [Select] <?php ini_set("SMTP","mySMTPserver."); ini_set("smtp_port","25"); ?> and now i get this msg... "Warning: mail(): SMTP server response: 503 5.5.2 Need Rcpt command." Code: [Select] <?php global $interface; global $user; if (isset($_POST['submit'])) { if(isset($_GET['userID'])){ $updateUser = new User(); if($user->id != $_GET['userID']){ $to = $updateUser->email; $subject = "Profile has been changed by " . $user->firstname . " " . $user->lastname; $message = " <html> <body> <h2>Notification</h2> <br /><br /> Hi, <br /><br /> This is an email notification you receive when your profile has been changed! </body> </html>"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; // More headers $headers .= 'From: admin@felnet.be' . "\r\n"; echo $to . " " . $subject . " " . $message . " " . $headers; if(mail($to,$subject,$message,$headers)){ $interface->assign('sent', "Success!"); }else{ $interface->assign('sent', "Fail!"); } } I really need help with this I have a php script that queries the database and then sends a separate email but I was just recently told they would like each query to to be put in an email so we only send one like the way i made it below (sorry if it's sloppy) if anyone can help I would greatly appreciate it. Thanks in advance ___________________________________ Name | Date | Address | State | _______|_____|______________|______ | John | 3/18 | 215 5th Street | NY | ______ |____ |______________|______ | Bob | 4/15 | 505 North Street | NY | ______ |____ |_____________ |______ | Jane | 5/9 | 6 main Street | MD | ______ |____|_______________ | ______| Ann | 1/12 | 9 West Ave | CA | ______ |____ |_______________|______ | Hi Sending mail problem, it going as plain text<?php include("global.php"); $Form_ID = $_GET['Form_ID']; $Page_ID = $_GET['Page_ID']; $Menu_ID = $_GET['Menu_ID']; $website_email = $g_setups[website_email]; $website_name = $Language_Website_Name; $website_link = $g_setups[website_link]; //get the Email Address from the Form Table #Email Address has taken from the Form Table,(may contain more than 1 email IDS) $email = "SELECT * FROM form where Form_ID = ".$Form_ID; $temps_email = $DB_site->query($email); $temp_email = $DB_site->fetch_array($temps_email); $add = explode("\n",$temp_email[Form_Email]); $address_count = count($add); $f=""; $frm = "SELECT * FROM field where Form_ID = ".$Form_ID; $temps = $DB_site->query($frm); while($temp = $DB_site->fetch_array()) { $value=""; //var_dump($_POST); //exit(); $nos = count($_POST["a".$temp[Field_ID]]); if($nos == 1) { $value = $_POST["a".$temp[Field_ID]]; } else { for($i=0;$i<$nos;$i++) { $value = $value.$_POST["a".$temp[Field_ID]][$i]; } } //echo $value; //exit(); $f = $f."<div style=' background-color:gray; clear:left;'><div style='float:left; width:150px; text-align:left; background-color:#f7f4f3;'>".$temp[Field_Name]."</div>". "<div style='float:left; width:350px; text-align:left; background-color:#f7f4f3;'>".$value."</div></div>"; } // Your email subject text $esubject = "Forms"; // Email Content //Get the Form Field Ids and Form Values and Mail It $emailtext = " <div style='width:500px; height=800px'> <div style='background-color:gray;'>Form</div> <div style=''><p>$f</p></div> </div> "; $headers = 'From: '.$website_name .'noreply@'.$website_link.'' . "\r\n" . 'Reply-To: noreply@'.$website_link.'' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); # This sends the email to you for($i=0;$i<$address_count;$i++) { //@mail("$add[$i]", $esubject, $emailtext, $header); mail("$add[$i]", $esubject, $emailtext, $header); //echo "send sucess"; } echo "<meta http-equiv=Refresh content=1;url='none.php?do=pagelink&Page_ID=$Page_ID&Menu_ID=$Menu_ID&mail_msg=sucess'>"; exit; ?> Thanks Hello all, I have a contact form which has a drop-down-menu (the reason why a user is using the form). I am wanting the option which has been selected to appear in the PHP scripted email as the subject. I am just sat here staring at the code and getting nowhere with it. Could anyone help me? HTML form Code: [Select] <form name="contact_form" method="post" action="mail.php" onsubmit="return validate_form();"> <p>Full Name <em>(required)</em>:<br /> <input class="tb-focus" type="text" name="name" id="name" size="40" value="" /></p> <p>Reason for Contact:<br /> <select class="select"> <option value="CV">CV Request</option> <option value="enquiry">General Enquiry</option> <option value="request">Request for Audition</option> </select> <p>Email Address <em>(required)</em>:<br /> <input class="tb-focus" type="text" name="email" id="email" size="40" value="" /></p> <p>Agency Name <em>(if applicable)</em>:<br /> <input class="tb-focus" type="text" name="business" id="business" size="40" value="" /></p> <p>Contact Number <em>(required)</em>:<br /> <input class="tb-focus" type="text" name="number" id="number" size="40" value="" /></p> <p>Message <em>(required)</em>:<br /> <textarea class="tb-focus" name="message" id="message" rows="6" cols="40"></textarea></p> <p><input class="button" type="submit" value="Submit Form" /></p> </form> PHP email POST: Code: [Select] <?php // Assign the posted values as variables to use later $name = $_POST['name']; $email = $_POST['email']; $reason = $_POST['sdsdsd']; $business = $_POST['business']; $number = $_POST['number']; $message = $_POST['message']; $to = "*********"; $subject = "Email Contact Form - " . $_POST[name]; $message = "Filled out contact form on portfolio website.\n \n Full Name: " . $_POST[name] . "\n Email: " . $_POST[email] . "\n Business Name: " . $_POST[business] . "\n Contact Number: " . $_POST[number] . "\n Message: " . $_POST[message]; //leave the next 2 lines alone $headers .= "MIME-Version: 1.0rn"; $headers .= "Content-Type: text/html; charset=ISO-8859-1rn"; if (empty($name) || empty($email) || empty($number) || empty($message)) { echo "<p>You appear to not have filled in the necessary fields.</p>"; echo "<p>Please click <a href='contact.html'>here</a> to re-enter your information.</p>"; } elseif(!mail($to, $subject, $message, $headers)){ echo "Sorry, there has been an error! Please try sending your message again. Click <a href='contact.htm'>here</a> to start again."; } else { echo "Thank you for taking the time to fill out the contact form. I will get back to you as soon as I can."; } ?> I have absolutely no idea where to start with this. Thanks in advance for the help So, I'm trying to make a script that will send emails from apparently anyone. Code: [Select] <?php $email = $_REQUEST['email'] $target = $_REQUEST['target'] $message = $_REQUEST['message'] $subject = $_REQUEST['subject'] mail( $target, $subject, $message, "From: $email" ); echo "Mail sent." ; ?> Here's the HTML, if it matters. Code: [Select] <html> <head> <title>EMAIL SPOOFER</title> </head> <body> <p>This program can make emails appear as if they came from any email address, real or fake!</p> <form method="post" action="mailspoof.php"> Apparent sender: <input name="email" type="text" /><br /> Subject: <input name="subject" type="text" /><br /> Recipient: <input name="target" type="text" /><br /> Message:<br /> <textarea name="message" rows="15" cols="40"> </textarea><br /> <input type="submit" /> </form> </body> </html> Here's the error I'm getting from my webhost: Parse error: syntax error, unexpected T_VARIABLE in /home/a5938041/public_html/mailspoof.php on line 3 If I know me, it's probably the most stupid mistake in the universe, so please point it out. ::) Problem with this header. $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "From: $to\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion(); $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $body = "<html><body>".$table."</body></html>"; Can anyone tell me why? I have a messaging system that I'm trying to send a notification by email to a specific person when a new message is entered. Everything is working fine except how the message is displayed in the email. Here's the problem: When the message reads: "This is a test. This should be two lines down. This is on the next line!" this is what is displayed in the email: "This is a test.\r\n\r\nThis should be two lines down.\r\nThis is on the next line!" How I'm displaying the message is by inserting it into a database first. Then I do a query to pull it back from the database on another page using the variable $message. I have tried using just $message and using nl2br("$message") and they both display as shown above. Does anyone have any ideas on how to get the message to display properly in the email? Here's the code that I'm using to send it in if it will help: Code: [Select] <?php $message2 = nl2br("$message"); $sendto2 = "$email"; $emailsubject2 = "New Message"; $emailmessage2 = "<html> <body> <table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td> $prefix $lname, <p> This message is to notify you that a new message has been sent. A copy of the message has been included below.<br> <hr width=\"500\"><br> <strong>Subject: \"$subject\"</strong> <p>$message2</p> Thank you! </td> </tr> </table> </body> </html>"; // To send HTML mail, the Content-type header must be set $headers2 = 'MIME-Version: 1.0' . "\r\n"; $headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers2 .= 'From: Admin <support@domain.us>' . "\r\n"; // Mail it mail($sendto2, $emailsubject2, $emailmessage2, $headers2); ?> Here is the code I have so far: <?php include('database.inc.php'); // Our database connectivity file ?> <?php $reminder_date = 't1.reminder_date'; $email = 'lp_reminder_email'; $reminder_name = 't1.reminder_name'; $reminder_details = 't1.reminder_desc'; $result = mysql_query($sql) or die(mysql_error()); $sql = "SELECT t1.`reminder_id` , t1.`reminder_name` , t1.`reminder_desc` , t1.`reminder_date` , t1.`reminder_email` , lp4.`email` AS `lp_reminder_email` FROM `reminder_events` AS t1 LEFT OUTER JOIN `authorize` AS lp4 ON ( t1.`reminder_email` = lp4.`email` ) WHERE reminder_date <= NOW() ORDER BY `reminder_date` ASC"; $result = 'mysql_num_rows'; while( $row = mysql_fetch_array( $result ) ) if( !empty( $nr ) ) ?> <?php $to = $row[$email]; $from = $row[$email]; $headers = $from; $subject = $row[$reminder_name]; $body = $row[$reminder_details]; { $send = @mail($to, $subject, $body, $headers); } ?> The sql query when run through phpMyAdmin returns a result. When I open this in the browser, it says "Query is empty". Anyone want to help a newb out and show me what I'm doing wrong? I'd like for it to pull the data out of these fields and send it via e-mail. What would be even better is if I could get it to do this the day before the `reminder_date`. I can set it up so cron runs the script, I just need to get the script to work first. Thanks in advance for your help. It works like a charm but the only problem I get when the page loads it SENDS an email without info of course because it sends it without someone pushing the submit button. Hereis my HTM Land PHP code Code: [Select] <form method="post" action="viewpage.php?page_id=5"> Email: <input name="email" type="text"><br> Message:<br> <textarea name="message" rows="15" cols="40"></textarea><br> <input type="submit"> </form> (note the action is in the page itself because thats where the php code is, now for the PHP code:) Code: [Select] <?php $to = "hidden for privacy"; $subject = "LoL Recruitment"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> For some reason I go to the page and it auto sends an email without waiting for me to "submit" the form... Is there any suggestions?? EDIT: I noticed its automatically doing the PHP script as soon as the page opens, because the HTML and PHP script is in the same "page" and not in different files, I understand this and I want it like this I dont want to have to create another file just for it to stop this bug. Theres got to be a way to pause the PHP script and activate it when the "Submit" button is pressed. I have been having some issues with the above functions and while the mail was sent , it was looking kinda weird Im facing 2 problems: 1st: implode() , or print_r() didnt worked for me , i guess i should be using a foreach statement but i never stadied seriously the arrays. 2nd: Always a JSON parse error, or invalid JSON error comes out when the email() code exitsts... Here is the code below Code: [Select] $name = trim(stripslashes(strip_tags($_POST['name']))); $email = trim(stripslashes(strip_tags($_POST['email']))); $url = trim(stripslashes(strip_tags($_POST['url']))); $title = trim(stripslashes(strip_tags($_POST['title']))); $anchortext = trim(stripslashes(strip_tags($_POST['anchortext']))); $description = trim(stripslashes(strip_tags($_POST['description']))); $dropdown = $_POST['dropdown']; $receiver = "example@gmail.com" ; $email_body = array($name,$email,$url,$title,$anchortext,$description,$dropdown); if (!empty($name) & !empty($email) && !empty($url) && !empty($title) && !empty($anchortext) && !empty($description) && !empty($dropdown) ){ // i guess all juice goes here ;) $send = mail($receiver, 'Link Exchange Request', "$email_body", "From: {$email}"); if ($send) { echo 'true'; } }I would like the mail to be presented like Name : blabla Email : blabla@blabla.com Url : blablablabla and so on .. Suggestions? Hello, i need to send emails to users according to the category they have selected everything works fine except for the mail function which tells me that i cannot parse an array variable. the error code is: Warning: mail() expects parameter 1 to be string, array given in C:\wamp\www\newsletter.php on line 25 can any1 tell me how i can send the mail so that it accepts that variable? my code is: Code: [Select] <?php $db_hostname="localhost"; $db_username="root"; $db_password=""; $db = mysql_connect($db_hostname,$db_username,$db_password); if (!$db) { die("Could not connect: " . mysql_error()); } mysql_select_db("newsletter", $db); if (isset($_POST['categories'])) { //make the checkmarks with name categories[] foreach ($_POST['categories'] as $cat) { $email_query = mysql_query("SELECT email FROM members WHERE `category` = '" . $cat . "'"); if (mysql_num_rows($email_query)) { while ($email = mysql_fetch_array($email_query)) { ini_set('SMTP','smtp.gmail.com'); if (mail($email, 'Subject','Message Goes Here', "From: <noreply@domain.com>")) { echo "Message Sent"; } else { echo "Message Not Sent"; } }//end while }// end if } } ?> Hi, I am having a problem with my Website mail. Basically the mail was working fine yesterday but last night I edited the PHP script slightly because for some reason the page that it was directed to had gone missing and was turning up an 404 error, which was just a newsuince as the email was still sent. So I just edited it so that it echo'ed a message saying thanks. but is seems today the mail is not getting to its destination. The PHP returns no errors and returns the success message fine but after saying its been sent it never appears. I have tried different email addresses on different servers and that was no use and I have also changed the code back to how it was yesterday. and it still doesn't work. I have also put the page up on one of my other sites which I know everything is set up properly and it works fine, making me think that it is a mail setup issue. but as I did not set up the mail at all and quite frankly don't really understand it, I don't know how it is meant to be set up as I just use google apps for sites that I set up. So yeah I am trying to work out what could have gone wrong since yesterday but I don't really understand it, below is the code as it as now and as it was yesterday: Code: [Select] <?php $EmailFrom = "johnshale@hotmail.co.uk"; $EmailTo = "matthale.live@gmail.com"; $Subject = "Website enquiry"; $Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> and the page is at www.sullyco.co.uk/contactengine.php as you can see the page is redirecting to a page that does not exist(contactthanks.php) indicating that the message was sent successfully. it is also the part I edited as a quick fix last night I just got it to echo a success message. Thanks for any help on this, I have been trying to work it out all morning, Matt Hi Friends, I did one contact.php and process.php(also i attached txt file). This process.php file send the data to my yahoo mail id. But i didnt receive any mails from this page. I dont know what i did the mistaken. so pls kindly send me you suggestion or feedback. waiting for your valuable suggestion. contact.php <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>testing - Contact Page</title> </head> <body> <form name="contact" method="POST" action="process.php"> <table width="456" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="28" valign="top">Your name:</td> <td><input name="name" type="text"></td> </tr> <tr> <td height="28" valign="top">E-mail address:</td> <td><input name="email" type="text"></td> </tr> <tr> <td height="28" valign="top">Contact No:</td> <td><input name="contact" type="text"></td> </tr> <tr> <td height="28" valign="top">Message:</td> <td><input name="message" type="text" /></td> </tr> <tr> <td> </td> <td valign="top" align="center"><input type="submit" value="Submit" name="submit"></td> </tr> </table> </form> </body> </html> process.php <?php if(isset($_POST['submit'])) { $to = 'vjn_23@yahoo.co.in'; //put your email address on which you want to receive the information $subject = 'hello'; //set the subject of email. $headers = 'MIME-Version: 1.0' . "\r\n". 'Content-type: text/html; charset=utf-8' . "\r\n". 'From: vijay@telltales.in' . "\r\n" . 'Reply-To: vijay@telltales.in' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr> <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr> <tr><td>Contact No</td><td>".$_POST['contact']."</td></tr> <tr><td>Message</td><td>".$_POST['message']."</td> </tr></table>" ; mail($to, $subject, $message, $headers); header('Location: contact.php'); } ?> Thank U, vjn_23 |