php mail problem

Discussion in 'PHP' started by Kyriakos, Oct 3, 2008.

  1. #1
    hi guys,

    i have a php mail script with smtp authontication:
    <?php
    $from = "DEFTEC <info@deftec.gr>";
    $to = "rallystas13@hotmail.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";
    
    $host = "89.234.63.108";
    $username = "info@deftec.gr";
    $password = "7791dima";
    
    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = mail::factory('smtp',
      array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password));
    
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }
    ?>
    PHP:
    the error message is this:
    line 14 is this $smtp = mail::factory('smtp',

    can anybody help me?
     
    Kyriakos, Oct 3, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    kmap, Oct 3, 2008 IP
  3. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try using this
    <?php
    // Setup
    $fromName = "Brian Salter";
    $fromEmail = "ns-survey@kcl.ac.uk";
    $fromMailer = "Socketmail v2.0";
    $smtp = "smtp.kcl.ac.uk";
    $smtp_port = 25;
    $charset = "ISO-8859-1";

    $toArray = file('Test data.csv'); // Read the whole file into an array
    // The file is in the format EMAIL, SCJ_CODE, SCE_SRTN
    $subject = "National Student Survey";

    $baseMessage="
    Reasons for non-participation (reply to ).

    ***SCJ_CODE SCE_SRTN
    I confirm that I do not wish to participate in the National Student Survey [ ]


    My reason for not participating is (please mark one of the following boxes and delete the other options):

    a)[ ] I do not wish my personal details to be used for the purposes of this survey

    b)[ ] I believe that participation will exacerbate my health difficulties

    c)[ ] I believe I have been wrongly selected for inclusion in the survey.


    Please note that instead of passing your personal contact details through to HEFCE/Ipsos, the above reason, in coded form, will be passed

    through instead.
    ";

    // Strip "\r" from the message (if it came from a form input)
    $baseMessage = str_replace(chr(13), "", $baseMessage);

    $baseMessage = str_replace("\r\n.", "\r\n..", str_replace("\n", "\r\n", stripslashes($baseMessage))." \r\n");

    ini_set('sendmail_from', $fromEmail);

    $connect = @fsockopen ($smtp, $smtp_port, $errno, $errstr, 5);
    if (!$connect) return false;
    $rcv = fgets($connect, 1024);

    // fputs($connect, "HELO {$_SERVER['SERVER_NAME']}\r\n");
    fputs($connect, "HELO 127.0.0.1\r\n");
    $rcv = fgets($connect, 1024);

    foreach ($toArray as $to) {

    $toBits = explode(",", $to);
    $toRcpt = trim($toBits[0]);
    $SCJ_CODE = $toBits[1];
    $SCE_SRTN = $toBits[2];

    $searchFor = array("SCJ_CODE", "SCE_SRTN");
    $replaceWith = array($SCJ_CODE , $SCE_SRTN );
    $message = str_replace($searchFor, $replaceWith, $baseMessage);

    fputs($connect, "RSET\r\n");
    $rcv = fgets($connect, 1024);

    fputs($connect, "MAIL FROM:$fromEmail\r\n");
    $rcv = fgets($connect, 1024);
    fputs($connect, "RCPT TO:$toRcpt\r\n");
    $rcv = fgets($connect, 1024);
    fputs($connect, "DATA\r\n");
    $rcv = fgets($connect, 1024);

    fputs($connect, "Subject: $subject\r\n");
    fputs($connect, "From: $fromName <$fromEmail>\r\n");
    fputs($connect, "To: $toRcpt\r\n");
    fputs($connect, "X-Sender: <$fromEmail>\r\n");
    fputs($connect, "Return-Path: <$fromEmail>\r\n");
    fputs($connect, "Errors-To: <$fromEmail>\r\n");
    fputs($connect, "Message-Id: <".md5(uniqid(rand())).".".preg_replace("/[^a-z0-9]/i", "", $fromName)."@$smtp>\r\n");
    fputs($connect, "X-Mailer: PHP - $fromMailer\r\n");
    fputs($connect, "X-Priority: 3\r\n");
    fputs($connect, "Date: ".date("r")."\r\n");
    fputs($connect, "Content-Type: text/plain; charset=$charset\r\n");
    fputs($connect, "\r\n");
    fputs($connect, $message);

    fputs($connect, "\r\n.\r\n");
    $rcv = fgets($connect, 1024);
    }

    fputs ($connect, "QUIT\r\n");
    $rcv = fgets ($connect, 1024);
    fclose($connect);
    ini_restore('sendmail_from');
    ?>
     
    singh.ajit05, Oct 3, 2008 IP
  4. Sillysoft

    Sillysoft Active Member

    Messages:
    177
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    PHPMailer is a great class to use for emailing, especially when using SMTP authentication:

    http://phpmailer.codeworxtech.com/
     
    Sillysoft, Oct 3, 2008 IP