I wrote a small script to send an email to my hotmail. The code run fine, no any error. However, I do not get any email yet. I am not sure how to debug. May I know the way to debug this problem. I also would like to know how to check where a server has been setup SMTP or not. It is not my server. I only can telnet to the server. Is there a way to find out?

Thanks

    Copy and save the below as info.php

    <?php
    phpinfo();
    ?>

    upload it to the root directory and type http://yoursite.com/info.php and you should see a long list of tables, in the second table you should see smtp= (something) where something could be localhost (the default)

    As far as your hotmail goes look in your junk mail folder since hotmail seems to put everything except stuff from them in that folder. Coul you possibly show the code for the mail() that you did do?

      Thanks for the reply.

      Yeah.

      <?php
      ......... }
      $recipient = "abcd@hotmail.com";
      $subject="Form Submission";
      error_reporting(0);
      if(mail($receipient,$subject,$msg,"testing")) {
      echo"<h1>Thank You !</h1><p>Message successfully sent:</p>\n";
      echo n12br($input);
      }
      else
      echo "Message not sent";
      }
      ......

      ?>

      I am not sure what I can do so that I would able to receive email generated from my PHP script. Is there any way to solve or I can do to solve this problem.

      Thanks

        You have in the additional headers position of your code information that PHP is not expecting the suntax for mail() is

        mail ( to, subject,  message [,  additional_headers [,  additional_parameters]] )

        The firs three are required and you have that part right. Your $msg must contain lines that are not longer than 70 characters and each line must be followed with a \n (newline) but the testing that you have in the optional parameter of additional headers should be stuff like

         'From: webmaster@example.com' . "\r\n" .
           'Reply-To: webmaster@example.com' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

        Notice the space after each : (colon)

          I would try this:

          <?php
          // specify a FROM address:
          $send = mail($receipient, $subject, $msg, 'From: you@yourdomanin.com' . "\r\n");
          
          if($send == true)
          {
          	echo '<h1>Thank You !</h1>' . "\n";
          	echo '<p>Message successfully sent:</p>' . "\n";
          	echo '<p>' . nl2br(htmlentities($input, ENT_QUOTES)) . '</p>';
          }
          else  {
          	echo '<h1>OOPS!</h1>' . "\n";
          	echo '<p>The message was <em>not</em> sent.</p>' . "\n";
          	echo '<p>Sorry. Please go back and try again.</p>';
          }
          ?>
          

            Thanks for the reply.

            I have tried both methods that you guys mentioned. I still do not received any email generated from my PHP script. I think it maybe doesn't have the mail service setup in the server. I have infor.php, which gives all the information on the server, but I am not sure how to read. I am pretty new to PHP. Do you have any suggession on where to start for looking into my problem.

            Thanks

            slyen

              To set up SMTP for your local server you need to edit your "working" php.ini file below is an example

              [mail function]
              ; For Win32 only.
              SMTP = mail.bna.bellsouth.net // change this to your ISPs email server
              smtp_port = 25
              
              ; For Win32 only.
              sendmail_from = someone@bellsouth.net //change this to your email address
              
              ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
              ;sendmail_path = "C:\Program Files\xampp\sendmail\sendmail.exe -t"
              
              ; 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 =

              After you edit your php.ini you should restart your webserver for it to see the changes in the php.ini. Then run a phpinfo and you should see the changes in the second table like the (click the link) ONE HERE. You might want to look at the PHP manual to learn how to properly set up your mail function to work for you by reading this mail() I will have a couple of examples that you can use or alter for your own circumstances.

                Is there an easy way to send a mass e-mail to, say, 300 people at once and avoiding timeout problems?

                Here's the code I have so far. Should this work with 300 people (and a relatively simple HTML file as the e-mail)?

                <?php
                include('Mail.php');
                
                $recipients = explode(";", $_POST["recipient_list"]);
                
                $headers['From'] = "newsletter@domain.com";
                $headers['To'] = "listaddr@domain.com";
                $headers['Subject'] = "Newsletter Test";
                
                $body = "<html><center><img src=\"http://www.domain.com/img.jpg\" /></center></html>";
                
                $params['sendmail_path'] = '/usr/lib/sendmail';
                
                $mail_object =& Mail::factory('sendmail', $params);
                
                $mail_object->send($recipients, $headers, $body);
                ?>

                  The mail() requires a to (recipients) and subject (with no newlines) and a message (with no lines linger than 70 characters and a \n ater each line) then for From: etcetera you would have each one seperate with a "\r\n". So then

                  $mail_object->send($recipients, $subject, $body, $headers); 

                  and $headers needs to be changed to

                  $headers  = 'MIME-Version: 1.0' . "\r\n";
                  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                  $headers .= 'From: newsletter@domain.com' . "\r\n";
                  $headers .= 'To: listaddr@domain.com' . "\r\n";
                  

                  You will not ned the subject in additional headers it should be in the $subject variable. See this section of the manual mail()

                    Thanks, Houdini.

                    The code I have actually works (aside from the MIME and HTML content-type that you pointed out -- thanks for that) if I just send it to one or two e-mail addresses. But do you reckon it would work if I sent it to about 300 e-mail addresses?

                    I would test it, but I'm scared to send it to the 300 e-mail addresses right now, because it might work for half of them or something weird like that, and then I'll have to send it again -- and that would be considered spam to the people who did receive it the first time. There are a lot of complications that make me scared to test it.

                      That should not matter as long as each recipient is comma seperated in your list, it will either send the maill to all of them or it will fail and not send it to any of them at all.

                      to
                      Receiver, or receivers of the mail.

                      The formatting of this string must comply with RFC 2822. Some examples are:

                      user@example.com
                      user@example.com, anotheruser@example.com
                      User <user@example.com>
                      User <user@example.com>, Another User <anotheruser@example.com>

                        Note that another requirement of RFC2822 is that header lines must not be more than 998 characters long, and should not be more than 78 characters long; trying to fit 300 addresses into a single line would definitely break the upper limit.

                          Also note that the PHP.net manual specifically warns users about using the native [man]mail/man function to send mass-amounts of emails if you break up the addresses into multiple calls to mail(). Why? Because it initiates a new connection to the MTA each time.

                          The PHP Manual wrote:

                          For the sending of large amounts of email, see the PEAR::Mail, and PEAR::Mail_Queue packages.

                            Thanks, guys.

                            For the upper limit, does that mean that I need to put a newline character every so often? Will that take care of that problem or will it create other problems?

                            As for the native mail() function: am I using that? I thought I was using some type of PEAR thing, but I may not be. I don't know much about PEAR and whatnot. I was thinking the code I had above was different from the native mail() function, but if not, please let me know.

                              You could use $message = wordwrap($message, 70); to automatically wordwrap after 70 characters and avoid the limit on 70 chars per line.

                                To be precise, the break string you'll want to use in wordwrap() is "\r\n\t"

                                RFC2822
                                2.2.3. Long Header Fields

                                Each header field is logically a single line of characters comprising the field name, the colon, and the field body. For convenience however, and to deal with the 998/78 character limitations per line, the field body portion of a header field can be split into a multiple line representation; this is called "folding". The general rule is that wherever this standard allows for folding white space (not simply WSP characters), a CRLF may be inserted before any WSP. For example, the header field:

                                Subject: This is a test

                                can be represented as:

                                Subject: This
                                	is a test

                                Note: Though structured field bodies are defined in such a way that folding can take place between many of the lexical tokens (and even within some of the lexical tokens), folding SHOULD be limited to placing the CRLF at higher-level syntactic breaks. For instance, if a field body is defined as comma-separated values, it is recommended that folding occur after the comma separating the structured items in preference to other places where the field could be folded, even if it is allowed elsewhere.

                                The process of moving from this folded multiple-line representation of a header field to its single line representation is called "unfolding". Unfolding is accomplished by simply removing any CRLF that is immediately followed by WSP. Each header field should be treated in its unfolded form for further syntactic and semantic evaluation.

                                  Thanks for the reply Houdini ...

                                    With so many mail server or clients software out there. I found that the header has to be set up with the right orders, otherwise, some of them will not work.

                                    Such as the headers like below

                                    $headers = 'MIME-Version: 1.0' . "\r\n";
                                    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
                                    $headers .= 'From: newsletter@domain.com' . "\r\n";
                                    $headers .= 'To: listaddr@domain.com' . "\r\n";

                                    The errors I run into is that

                                    1) $headers = 'MIME-Version: 1.0' . "\r\n";

                                    if this line is the first line as in the sample, sometimes, the email I received are without From: information, and html email is broken with html tags shown.

                                    and 'MIME-Version: 1.0' . "\r\n"; cannot be the first line, and cannot be put before headers "From", it has to be put behind 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                                    Why?

                                    2) if without 'MIME-Version: 1.0' . "\r\n"; my squirrelmail cannot read the html email, it will show tags.

                                    So I have to put 'MIME-Version: 1.0' . "\r\n"; in the headers, and it has to be behind the header of content type. This seems satisfy all the situations. But at the same time, I got the MIME-Version: 1.0 shows in the message body part when I download the email to my desk top and read it with outlook express.

                                    Could anyone give a headers sample in the right order with only very necessary headers for html email?

                                    Thanks!

                                      $headers = "From: $email_from\r\n";
                                      $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; //content type
                                      $headers .= "MIME-Version: 1.0\r\n";

                                      I seems that if I want the mail() work on most platforms, I have to set up the headers like above, and in the exact orders.

                                      Is there a standard that headers in which order and which headers are required for html email?

                                      Thanks!

                                        serain wrote:

                                        Is there a standard that headers in which order and which headers are required for html email?

                                        Long answer:

                                        RFC2822
                                        3.6 Field Descriptions
                                        It is important to note that the header fields are not guaranteed to be in a particular order. They may appear in any order, and they have been known to be reordered occasionally when transported over the Internet.

                                        Short answer: no. If a mail client can't tolerate them being in any order, it's buggy.