marczs Posted March 23, 2007 Share Posted March 23, 2007 Hi i'm new at PHP , i'm trying to learn .... I'm trying to set a script to send an email with information from a form. It's quite simple ... I got various sample scripts from internet , but when i run them , i get the message "mesage sent" but i never get the mail .... Anyone can help me ? Thanks a lot ! MArc Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 23, 2007 Share Posted March 23, 2007 Why don't you share your code with us so we can help you debug it? Quote Link to comment Share on other sites More sharing options...
jitesh Posted March 23, 2007 Share Posted March 23, 2007 You can download and use PHPmailer class. Quote Link to comment Share on other sites More sharing options...
DeathStar Posted March 23, 2007 Share Posted March 23, 2007 mail() function.. And try reading some posts to figure out what is wrong next time! Like mine: http://www.phpfreaks.com/forums/index.php/topic,132667.0.html Quote Link to comment Share on other sites More sharing options...
marczs Posted March 23, 2007 Author Share Posted March 23, 2007 Sorry i forgot to share the code the code i'm trying to use is ...... <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; ?> <form name="form1" method="post" action="<?php echo $me;?>"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><font size="2" face="Frutiger 45"> </font></td> <td><font size="2" face="Frutiger 45"> </font></td> <td><font size="2" face="Frutiger 45"> </font></td> </tr> <tr> <td width="10"> <div align="center"><font size="2" face="Frutiger 45"> · </font></div> </td> <td><font size="2" face="Frutiger 45">Nombre : </font></td> <td><font size="2" face="Frutiger 45"> <input name="nom" type="text" class="logisticaimes" size="50" maxlength="50"> </font></td> </tr> <tr> <td><div align="center"><font size="2" face="Frutiger 45">·</font></div></td> <td><font size="2" face="Frutiger 45">Teléfono : </font></td> <td><font size="2" face="Frutiger 45"> <input name="telefon" type="text" class="logisticaimes" size="30" maxlength="9"> </font></td> </tr> <tr> <td><div align="center"><font size="2" face="Frutiger 45">·</font></div></td> <td><font size="2" face="Frutiger 45">Email : </font></td> <td><font size="2" face="Frutiger 45"> <input name="email" type="text" class="logisticaimes" size="50" maxlength="50"> </font></td> </tr> <tr> <td width="20" valign="top"> <div align="center"><font size="2" face="Frutiger 45">·</font></div></td> <td valign="top"><font size="2" face="Frutiger 45">Comentarios : </font></td> <td><font size="2" face="Frutiger 45"> <textarea name="comentaris" cols="40" rows="10" class="logisticaimes"></textarea> </font></td> </tr> <tr> <td> </td> <td> </td> <td><input name="Submit" type="submit" class="logisticaimes" value="Enviar"></td> </tr> </table> </form> <font face="Frutiger 45"> </font></td> <td width="37%"><div align="right"><img src="imatges/contacte_imatge.jpg" width="289" height="336"></div></td> </tr> </table></td> </tr> <tr> <td><img src="imatges/sub_dades.jpg" width="781" height="19"></td> </tr> </table> <?php } else { error_reporting(0); $recipient = 'marczs@gmail.com'; $subject = stripslashes($_POST['email']); $from = stripslashes($_POST['nom']); $msg = "Message from: $from\n\n".stripslashes($_POST['comentaris']); if (mail($recipient, $subject, $msg)) echo nl2br("<b>Message Sent:</b> To: $recipient Subject: $subject Message: $msg"); else echo "Message failed to send"; } ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 This is probably posted on the forum a thousand times. http://us3.php.net/manual/en/function.mail.php Note the Headers and the -f Example 1049. Sending mail with extra headers. The addition of basic headers, telling the MUA the From and Reply-To addresses: <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> Example 1050. Sending mail with an additional command line parameter. The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path. <?php mail('nobody@example.com', 'the subject', 'the message', null, '-fwebmaster@example.com'); ?> Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 23, 2007 Share Posted March 23, 2007 My guess is that you're actually getting the email, but since it's going to GMail, it's getting dumped in your spam folder. Check that out first and see if GMail is filtering them out. Without the "-f" option that frost mentions above, it is actually coming from your apache or root user, not the address you want it to come from. Quote Link to comment Share on other sites More sharing options...
marczs Posted March 25, 2007 Author Share Posted March 25, 2007 Thanks everybody for your help. I'm using this script : <?php $to = 'marczs@gmail.com'; $subject = 'the subject'; $message = 'hello'; $html = false; $headers = "MIME-Version: 1.0" . "\r\n"; if($html) { $headers .= "Content-type: text/HTML; charset=ISO-8859-1" . "\r\n"; } else { $headers .= "Content-Type: text/plain; charset=ISO-8859-1" . "\r\n"; } $headers .= "From: \"$from_name\" <" . $from . ">" . "\r\n"; $headers .= "Reply-To: $from" . "\r\n"; mail($to, $subject, $message, $headers,'-fmarczs@gmail.com'); ?> ..... and it works on one server..... i correctly get the email and even not in the spam folder, but when i try it in the customer's server , i don't get the email . any idea ? Quote Link to comment Share on other sites More sharing options...
DeathStar Posted March 25, 2007 Share Posted March 25, 2007 Arg... [ code ][ /code ] Please! Quote Link to comment Share on other sites More sharing options...
marczs Posted March 26, 2007 Author Share Posted March 26, 2007 Sorry ... Thanks everybody for your help. I'm using this script : <?php $to = 'marczs@gmail.com'; $subject = 'the subject'; $message = 'hello'; $html = false; $headers = "MIME-Version: 1.0" . "\r\n"; if($html) { $headers .= "Content-type: text/HTML; charset=ISO-8859-1" . "\r\n"; } else { $headers .= "Content-Type: text/plain; charset=ISO-8859-1" . "\r\n"; } $headers .= "From: \"$from_name\" <" . $from . ">" . "\r\n"; $headers .= "Reply-To: $from" . "\r\n"; mail($to, $subject, $message, $headers,'-fmarczs@gmail.com'); ?> ..... and it works on one server..... i correctly get the email and even not in the spam folder, but when i try it in the customer's server , i don't get the email . any idea ? Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 26, 2007 Share Posted March 26, 2007 May be totally off base here, but definitely worth trying: I once worked on a server that had the scripts screen all your "from" and "-f" addresses. If they were not addresses hosted on the server that the message was being sent from, the message would be blocked from going out. This helped to guard them against being spam agents, I guess. Try your script again with sending from a valid email address hosted on the same server (or at least domain) that your script is running on. For instance, if you're running the script on www.mydomain.com, try sending it from admin@mydomain.com or something similar. My best guess is that you're actually getting into server configuration differences that will need to be sorted out. One other thought is that you may want to consider actually sending via SMTP connection rather than depending on using the sendmail or like script. Hope some of this is helpful. Good luck! Quote Link to comment Share on other sites More sharing options...
marczs Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks ! I'll try it .... i thought about the fact that you cannot send mail to adresses outside the domain .... thanks again! Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 26, 2007 Share Posted March 26, 2007 Hi Im having the same problem as Marczs. Tried all sorts but the mail never arrives. Currently I am sending the mail from and to the same address which is hosted on the domain. e.g darren.rhymer@mydomain.com. When i use WebMail I can send from and recieve mail to this account. Its weird. The domain is hosted by FastHosts on a Windows server. You got it working Marczs? Quote Link to comment Share on other sites More sharing options...
marczs Posted March 26, 2007 Author Share Posted March 26, 2007 Hi DazlerD ! I'll try it tonight. I'll try to configure it with the adress from my costumer's domain .... In a few hours i'll tell you . Is it working for you when you send mails from the same domain ? Thanks ! Quote Link to comment Share on other sites More sharing options...
Lethal.Liquid Posted March 26, 2007 Share Posted March 26, 2007 Well...your server might not have the function...also, are you sure you can recieve? Have you tried to recieve mail from a different domain? Quote Link to comment Share on other sites More sharing options...
anthonydamasco Posted March 26, 2007 Share Posted March 26, 2007 the customers server has to have a email setup for outgoing mail Quote Link to comment Share on other sites More sharing options...
DazlerD Posted March 27, 2007 Share Posted March 27, 2007 Hi Ive just tried sending email from the server using WebMail to hotmail and it gets received fine. The message can be replied to and gets received. So I know the email works, but why wont mail() in the PHP send mail? Lethal, if the server doesnt have the function to send mail() then surely this would come back with an error not success. marczs: Yeah ive tried sending from and to darren.rhymer@mydomain.com. Just doesnt work. Quote Link to comment Share on other sites More sharing options...
DazlerD Posted April 27, 2007 Share Posted April 27, 2007 This probably wont be the same for any other server, but for FastHosts you need to include the line: ini_set("sendmail_from", 'email@mydomain.com'); It then works great. Darren 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.