Mail() Script OK?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chunk1978
    New Member
    • Jan 2007
    • 224

    Mail() Script OK?

    hi there... i would like to know if anyone could look at my mail script and tell me if there is anything clearly wrong, or missing...

    Code:
    <?php
    $to = $_POST['email'];
    $subject = 'test';
    $random_hash = md5(date('r', time())); 
    
    $headers = "From: me@example.com\nReply-To: me@example.com";
    $headers .= "\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
    
    ob_start();
    ?>
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 8bit
    
    <?php
    echo nl2br ("this is a basic text email message.\nYour Email doesn't accept HTML email.");
    ?>
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 8bit
    
    <?php
    echo ("<h2>this is an HTML email</h2>");
    echo ("<p>Your email accepts <b>HTML</b> formatting.</p>");
    ?>
    
    --PHP-alt-<?php echo $random_hash; ?>--
    
    
    
    <?
    $message = ob_get_clean();
    mail ($to, $subject, $message, $headers);
    # after message is sent, goto Google.
    header ("Location:  http://www.google.com");
    ?>
    i'm planning on just using the PHP Mail() function... i'm under the assumption that it's possible to send Text and HTML emails without having to use PHP Mailer or something similar. please let me know if i'm wrong here...

    thanks in advance
  • chunk1978
    New Member
    • Jan 2007
    • 224

    #2
    anyone at all? i could really use someone's help.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      What are you looking for? You have not asked us a question, which makes it quite difficult to answer your question.

      The mail() function in PHP relies on your server's SMTP settings. You will need to have an SMTP server running, and have PHP configured properly to use it.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Im not sure what the problem with your script is.

        Here is a sample script of how to use the mail() function tho:
        Sample script

        Comment

        • chunk1978
          New Member
          • Jan 2007
          • 224

          #5
          sorry for the confusion... i was simply posting this script to see if anyone could spot any syntax errors or something else that would be way wrong with it...

          thanks for making me realize that smtp email is required for the sendmail function... i was under the impression that you could write any address is the $header From: section for it to work... but i suppose it's a security/spam risk to allow that... i guess i'll have to wait until monday to test my php mail scripts when i order my server space...

          Comment

          • chunk1978
            New Member
            • Jan 2007
            • 224

            #6
            hello again... i recently subscribed to a server so i'm able to test my PHP Mail() scripts. this example above sends, but when i open the email (in my GMAIL account), body of the email is missing (neither the text or html versions are displayed)...

            can anyone tell me what's wrong with the code?

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              I doubt this will change anything, but you could try changing the "\n" in the header to "\r\n".
              "\r\n" is the Windows version of the old "\n" unix newline character.

              Comment

              • chunk1978
                New Member
                • Jan 2007
                • 224

                #8
                Originally posted by Atli
                I doubt this will change anything, but you could try changing the "\n" in the header to "\r\n".
                "\r\n" is the Windows version of the old "\n" unix newline character.
                hi there... i'm on a *nix server... so \r isn't necessary...

                Comment

                • chunk1978
                  New Member
                  • Jan 2007
                  • 224

                  #9
                  Originally posted by chunk1978
                  hi there... i'm on a *nix server... so \r isn't necessary...
                  also... this is exactly what is being sent to the email address... but it seems fine to me... and if this is showing up when i click 'show original message' why isn't anything appearing in the email?

                  Code:
                  <removed - contains personal information that could be used for malicious purposes>
                  Last edited by zmbd; Sep 8 '18, 05:10 AM. Reason: [z{redacted personal information per request and site policy}]

                  Comment

                  • ValHolla
                    New Member
                    • Sep 2006
                    • 8

                    #10
                    Originally posted by chunk1978
                    also... this is exactly what is being sent to the email address... but it seems fine to me... and if this is showing up when i click 'show original message' why isn't anything appearing in the email?

                    Code:
                    <removed - contains personal information that could be used for malicious purposes>

                    I am not sure if this is the cause, but try a different encoding. MIME "should" be accepted by all mail servers.

                    http://us.php.net/function.mail for examples on sending HTML email.
                    Last edited by zmbd; Sep 8 '18, 05:11 AM. Reason: [z{redacted personal information per request and site policy}]

                    Comment

                    • chunk1978
                      New Member
                      • Jan 2007
                      • 224

                      #11
                      Originally posted by ValHolla
                      I am not sure if this is the cause, but try a different encoding. MIME "should" be accepted by all mail servers.

                      http://us.php.net/function.mail for examples on sending HTML email.

                      hello... i've changed the charset to "us-ascii" and "utf-8", i've also changed the Content-Transfer-Encoding: 8bit to both 7bit and base64... it's still not displaying in my gmail...

                      i'm comparing my own test email to other multipart/alternitive messages i've received that do display in gmail... the code in the messages that do display is the same as my code...

                      i'm afraid i'm stuck...

                      Comment

                      • chunk1978
                        New Member
                        • Jan 2007
                        • 224

                        #12
                        it seems to work now... but i haven't fully tested it...

                        i had to remove the very last boundary that was included in my script after the HTML code...

                        Comment

                        • samvb
                          New Member
                          • Oct 2006
                          • 228

                          #13
                          hi guys...

                          i ve almost same problem...i am using argosoft mail server pro and added a domain called moh.com with a user named kif. The website is not yet published, but we have an internal network that we use using the mail server. Now, I have my email address <email removed>, and from my php file, it sends it. At least, thats what I see in my mail server log file: that it has sent a msg to <email removed>. But when I log on to my <email removed>.com, I dont get the msg. What could be the wrong?
                          Last edited by zmbd; Sep 8 '18, 05:13 AM. Reason: [z{redacted personal information per request and site policy}]

                          Comment

                          • chunk1978
                            New Member
                            • Jan 2007
                            • 224

                            #14
                            Originally posted by samvb
                            hi guys...

                            i ve almost same problem...i am using argosoft mail server pro and added a domain called moh.com with a user named kif. The website is not yet published, but we have an internal network that we use using the mail server. Now, I have my email address <email removed>, and from my php file, it sends it. At least, thats what I see in my mail server log file: that it has sent a msg to <email removed>. But when I log on to my <email removed>.com, I dont get the msg. What could be the wrong?
                            hi samvb... if you have the same problem as i do, then you're boundaries are not correct... however, i've learned that sending multipart/alternitive mail thru PHP can be quite complex, and therefore your problem could be one of many things.

                            have you read thru the mail thread on php.net? there are quite a few examples and explanations that you can read... and you're also welcome to post your code here so others can possibly see exactly what the problem is... i hope this link helps, as it's what helped me.



                            good luck
                            Last edited by zmbd; Sep 8 '18, 05:14 AM. Reason: [z{redacted personal information per request and site policy}]

                            Comment

                            Working...