Jump to content

send an email


marczs

Recommended Posts

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

Link to comment
Share on other sites

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";

}

?>

Link to comment
Share on other sites

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');

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 5 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.