kney Posted August 30, 2011 Share Posted August 30, 2011 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) <?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: <?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." <?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!"); } } Quote Link to comment Share on other sites More sharing options...
trq Posted August 30, 2011 Share Posted August 30, 2011 Do you have a mail server installed and configured? Quote Link to comment Share on other sites More sharing options...
kney Posted August 30, 2011 Author Share Posted August 30, 2011 No, but I used the smtp server from my company to send the mail And the fact that the code in the first part sends the mail, and the second code (which is the same) doesn't, is weird Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 30, 2011 Share Posted August 30, 2011 try this code $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: $from\r\n"; Quote Link to comment Share on other sites More sharing options...
kney Posted August 30, 2011 Author Share Posted August 30, 2011 I get the same error "Warning: mail(): SMTP server response: 503 5.5.2 Need Rcpt command. in C:\vufind\web\services\MyResearch\Edit.php on line 178 " Quote Link to comment Share on other sites More sharing options...
trq Posted August 30, 2011 Share Posted August 30, 2011 This is not a coding issue but a configuration issue. I would speak to whomever maintains the mail server. Quote Link to comment Share on other sites More sharing options...
kney Posted August 30, 2011 Author Share Posted August 30, 2011 Could be, but how in earth is it possible to send the mail in the first part of the code and not in the second, while no configuration had been edited. Quote Link to comment Share on other sites More sharing options...
trq Posted August 30, 2011 Share Posted August 30, 2011 There is only a single call to mail() in the code you have posted. Quote Link to comment Share on other sites More sharing options...
kney Posted August 30, 2011 Author Share Posted August 30, 2011 1st part.. from Borrow.php <?php 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!"); } ?> 2nd part... from Edit.php <?php if(mail($to,$subject,$message,$headers)){ $interface->assign('sent', "Success!"); }else{ $interface->assign('sent', "Fail!"); } ?> Quote Link to comment Share on other sites More sharing options...
kney Posted August 31, 2011 Author Share Posted August 31, 2011 it still won't work.. pls help Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 31, 2011 Share Posted August 31, 2011 Run this code on a new page. ( $to = put u email address) <?php $to = "email address"; $from = " <no-reply@sitename.info >"; $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: $from\r\n"; $mail_body = "Hello World"; if (mail($to,"Mail", $mail_body,$headers)) { echo " Thankyou! - Your feedback has been sent! "; } else { echo " Thankyou! - We could not send email. Please try later! "; } Quote Link to comment Share on other sites More sharing options...
kney Posted August 31, 2011 Author Share Posted August 31, 2011 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\bibManageDocuments.php on line 24 Thankyou! - We could not send email. Please try later! so i added this code , and now it works.. and on the Edit.php it doesn't work <?php ini_set("SMTP","smtp.vito.local"); ini_set("smtp_port","25"); ?> Quote Link to comment Share on other sites More sharing options...
kney Posted August 31, 2011 Author Share Posted August 31, 2011 The problem was in this part.. I created a new user but didn't specify which user to get the email address from. It's fixed now! Thanks for the help <?php $updateUser = new User(); // added this now // ------------------- $updateUser->get('id', $_GET['userID']); // ------------------- $to = $updateUser->email; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.