SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Mailing list!

    I have created a simple php mailing script seeing a tutorial. But the problem is the script works but the email doesn't go. I got stuck with the mail host thingy. The guy uses his mailhost code like

    ini_set("SMTP", "mailhost.*******.co.uk");

    So I got stuck with this, what should be my mailhost, I have a domain with hosting. The provider just gave me three addresses which are

    cpanel.*******.com
    webmail.********.com
    ftp.********.com

    So how should I write the code, and I also got 10 POP3 email, i made some email accounts with it but how can I send the emails?

    here is my code for index.php and send.php:


    Code PHP:
    <?php
    require ('connect.php');
     
     
    echo "<h1>Mailing List</h1> Send to <p>";
     
    echo "<form action='send.php' method='GET'>";
     
    //setup variable
    $mailcount = 0;
    $namecount = 0;
    $get = mysql_query("SELECT * FROM mailinglist where send='1'");
     
    while ($getrow = mysql_fetch_assoc($get))
    {
    echo "<input type = 'checkbox' name='mail_".$mailcount++."' value'".$getrow['email']."' CHECKED><br>".$getrow['firstname']." ".$getrow['lastname']." (".$getrow['email'].")<br>";
    }
     
     
     
     
     
    echo "</form>"
     
     
    ?>

    here is send.php


    Code PHP:
    <?php
     
     
    require ('connect.php');
     
    //change php.ini SMTP file
    ini_set("SMTP", "mailhost.*******.co.uk");  <-------This line, please help
     
     
    //standard mail header
     
    $headers = "foodecrp@split.starhostbd.com";
     
    //get message
     
    //loop through
    for($x=0; $x<count($_GET);$x++)
    {
       if ($_GET["mail_$x"])
       {
     
     
    	//mail setup
    		$to = $_GET["mail_$x"];
    		$subject = "Newsletter";
    		$body = "Dear ".$_GET["name_$x"]."
    		\n\n $message \n\n
    		FoodieCorp.
    		";
     
    		mail($to, $subject, $body, $header);
     
     
       }
     
    }
     
     
     
    echo "All email has been processed.";
     
     
     
     
     
    ?>

  2. #2
    SitePoint Member battambang_kid's Avatar
    Join Date
    Feb 2012
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why need to change your mailhost?
    if you have a hosting, the mailhost configuration should be already setup.

    try remove the line ini_set("SMTP", "mailhost.*******.co.uk");

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by battambang_kid View Post
    why need to change your mailhost?
    if you have a hosting, the mailhost configuration should be already setup.

    try remove the line ini_set("SMTP", "mailhost.*******.co.uk");
    Well I meant what should I write in that line? any address of mine? I tried removing the ini set line but the emails doesnt go, but the message appears all emails has been processed

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you need to remove the line ini_set, as this will overide the default mail setings for php.

    your script will always tell you the mail has been processed as it is not checking only printing.

    You also need to have more headers for most SMTP servers to accept to send your mail

    change send.php for this and try

    PHP Code:
    <?php
    require ('connect.php');
    $badmail 0;
    $goodmail =  0

    //standard mail header
     
    $headers "MIME-Version: 1.0\r\n"
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"
    $headers .= "From: you@yourdomain.com\r\n";  // change this address
    $headers .= "Reply-To: you@yourdomain.com\r\n";  // and this one
    $headers .= "X-Priority: 1\r\n"
    $headers .= "X-MSMail-Priority: High\r\n"
    $headers .= "X-Mailer: PHP \r\n";
      
    //get message
     
    //loop through
    for($x=0$x<count($_GET);$x++)
    {
       if (
    $_GET["mail_$x"])
       {
     
     
    //mail setup
    $to $_GET["mail_$x"];
    $subject "Newsletter";
    $body "Dear ".$_GET["name_$x"]."
    \n\n 
    $message \n\n
    FoodieCorp.
    "
    ;
     
    if (
    mail($to$subject$body$headers)){
    $goodmail++;
    }else{
    $badmail ++;
    }
     
     
       }
     
    }
     
     
     
    echo 
    "$goodmail emails sent - $badmail emails not sent.";
     
    ?>
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    you need to remove the line ini_set, as this will overide the default mail setings for php.

    your script will always tell you the mail has been processed as it is not checking only printing.

    You also need to have more headers for most SMTP servers to accept to send your mail

    change send.php for this and try

    PHP Code:
    <?php
    require ('connect.php');
    $badmail 0;
    $goodmail =  0

    //standard mail header
     
    $headers "MIME-Version: 1.0\r\n"
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"
    $headers .= "From: you@yourdomain.com\r\n";  // change this address
    $headers .= "Reply-To: you@yourdomain.com\r\n";  // and this one
    $headers .= "X-Priority: 1\r\n"
    $headers .= "X-MSMail-Priority: High\r\n"
    $headers .= "X-Mailer: PHP \r\n";
      
    //get message
     
    //loop through
    for($x=0$x<count($_GET);$x++)
    {
       if (
    $_GET["mail_$x"])
       {
     
     
    //mail setup
    $to $_GET["mail_$x"];
    $subject "Newsletter";
    $body "Dear ".$_GET["name_$x"]."
    \n\n 
    $message \n\n
    FoodieCorp.
    "
    ;
     
    if (
    mail($to$subject$body$headers)){
    $goodmail++;
    }else{
    $badmail ++;
    }
     
     
       }
     
    }
     
     
     
    echo 
    "$goodmail emails sent - $badmail emails not sent.";
     
    ?>
    Tried man doesn't work. says 2 emails sent but I get nothing in my inbox but failure message in my header email outbox. Okay I got into cpanel and saw some Outgoing mail server and outgoing mail server (SSL) settings as below:


    Manual Settings
    Mail Server Username: foodecrp
    Incoming Mail Server: mail.******.com
    Incoming Mail Server: (SSL) split.*******bd.com
    Outgoing Mail Server: mail.*******.com (server requires authentication) port 466
    Outgoing Mail Server: (SSL) split.*******bd.com (server requires authentication) port 465
    Supported Incoming Mail Protocols: POP3, POP3S (SSL/TLS), IMAP, IMAPS (SSL/TLS)
    Supported Outgoing Mail Protocols: SMTP, SMTPS (SSL/TLS)



    i tried with these Outgoing mail server on Php ini set in my 1st send.php file apart from yours with these, still I get no emails but failure messages.



    This message was created automatically by mail delivery software.

    A message that you sent could not be delivered to one or more of its
    recipients. This is a permanent error. The following address(es) failed:

    on@split.starhostbd.com
    Unrouteable address

    ------ This is a copy of the message, including all the headers. ------

    Return-path: <foodecrp@split.********.com>
    Received: from foodecrp by split.********.com with local (Exim 4.69)
    (envelope-from <foodecrp@split.********.com>)
    id 1S0ObS-0001K2-9D
    for on@split.********.com; Wed, 22 Feb 2012 20:39:54 -0600
    To: on@split.********.com
    Subject: Newsletter
    X-PHP-Script: *********.com/send.php for 99.43.202.106
    Message-Id: <E1S0ObS-0001K2-9D@split.********.com>
    From: foodecrp@split.********.com
    Date: Wed, 22 Feb 2012 20:39:54 -0600




    Please advise!!


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
  •