SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem while sending emails

    I have a small script that sends an email to several users.

    PHP Code:
    $to $email1 ", " $email2 ", " $email3;
    $subject "Subject";
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $message ''// HTML message
    mail($to,$subject,$message,$headers); 
    Until now there are no problems. The problems start to appear if I want to send an email to the currently logged in user, based on their privilege:

    PHP Code:
    // This section comes right after the first part above
    if ($_SESSION['privilege'] < 2) {
      
    $message '';
    } else {
      
    $message ''// different HTML message
    }
    mail($useremail,$subject,$message,$headers);

    header('Location: home.php'); 
    Now if I click on the form button, I don't receive any more emails and the redirect to the homepage fails with a "File not found error", telling me to check that the filename doesn't contain uppercase letters or typos and to check if the file was moved, renamed or deleted.

    Do you have any idea why this is happening?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Try putting something inside the messages.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Try putting something inside the messages.
    LOL I may be stupid but not up to this point XD

    The HTML messages are pretty long and contain information retrieved from a database, therefore it would have been useless to post them here in their entirety.

    Here's a test message:
    PHP Code:
    $message '
    <html>
      <head>
        <title>Title</title>
      </head>
      <body>
        <h1>Email title</h1>
        <p>Test message</p>
      </body>
    </html>'


  4. #4
    SitePoint Addict D3V4's Avatar
    Join Date
    May 2010
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any ideas?

    Is there maybe another way to send different email messages to different email addresses?

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    is mail() returning true or false? Throw it into an if and use a variable on the end of the header to catch it.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The to parameter in the mail() function can only accept one email address. You might try adding the extra email addresses into the headers as a CC or BCC field.

    PHP Code:
    // $to = $email1 . ", " . $email2 . ", " . $email3;
    $subject "Subject";
    $headers "Bcc: " $email2 ", " $email3 "\r\n";
    $headers  .= 'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $message ''// HTML message
    // mail($to,$subject,$message,$headers);
    mail($email1,$subject,$message,$headers); 
    CanisHosting - Web Hosting plans starting at $3.95 per month

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sparek View Post
    The to parameter in the mail() function can only accept one email address. You might try adding the extra email addresses into the headers as a CC or BCC field.
    That statement is not correct. I regularly use multiple email addresses in the "to" field (separated by commas). The PHP spec also states that multiple recipients are permitted in the "to" field.

  8. #8
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please try this as I use this to send email to several addresses regularly via CRON . You may simply read any html file on your or any server and read and send same as html email.


    <?php

    $message = file_get_contents('http://www.yourdomain.com/foldername/htmlfiletoemail.html');

    $to = "mailto@domain.com";


    $subject = "Your subject goes here ";

    echo $message;


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

    $headers .= "Content-type: text/html\r\n";

    $headers .= 'From: Your Name <you@yourdomain.com>' . "\r\n";
    $headers .= 'To: Your Customer Name <yourcustomername@domain.com>, Another Name <anothername@email.com>,
    Yet Another Name <anothername1@email.com>, One More Name <onemorename@domain.com>' . "\r\n";
    $headers.= 'Cc: copyto@domain.com' . "\r\n";
    $headers.= 'Bcc: you@yourdomain.com' . "\r\n";

    mail($to, $subject, $message, $headers);


    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •