Help with mail in script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • adonairc
    Sergeant

    • Oct 2005
    • 36

    Help with mail in script

    Hi, i'm writing this because i'm thinking in cut my veins with a lettuce leaf, I have passed weeks and weeks trying to change the way scripts send php mail in order to be sent trough authenticated smtp and i don't find the way.

    I've tried php mailer, smtp.class, and a lot of scripts found in google and nothing; I don't know if anyone here can help me.

    The next is a code of a script, when a user register itself, it's suposed to receive a confirmation mail... but of course, nothing happens because uses the php mail function.

    PHP Code:
    <?
    $result = mysql_query("SELECT * FROM $membtable WHERE m_user='$en[user]' OR m_email='$en[email]' LIMIT 1") or die(mysql_error());
    $line = mysql_fetch_assoc($result);
    if (mysql_num_rows($result) == 0) {
    $en['send_result'] = _sent_code_fail;
    } else {
     
    $temp = '';
    for ($k = 1;$k<=7;$k++)
    $temp .= chr(97+rand(0,25));
    $en = array_merge($line,$en);
    $en['pass'] = $temp;
    $mail = emailtemplate('emails/send_password.tpl');
     
    mail($line[m_email], $mail[subj], $mail[body],
    "From: ".admin_email."\r\n"
    ."Reply-To: ".admin_email."\r\n"
    ."X-Mailer: PHP/" . phpversion());
    mysql_query("UPDATE $membtable SET m_pass='".md5($temp)."' WHERE m_id=$line[m_id]") or die(mysql_error());
    $en['send_result'] = _pass_sent.' <b>'.$line[m_email].'</b>';
    }
    load_template(tpl_path.'password_sent.tpl');
    ?>
    If any body can help me I'll be very thankful.

    Ado
  • Watdaflip
    Major General

    • Sep 2005
    • 2116

    #2
    Re: Help with mail in script

    I use phpmailer, it works fine, perhap you weren't using it correctly, here some code that should work, just change it to fit your needs

    <?php
    require("class.phpmailer.php");

    $email_from = "admin@mysite.com";
    $email_subject = "Hello";
    $email_message = "Email Message";
    $email_to = $_POST['email'];

    $mail = new PHPMailer();
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host = "localhost"; // SMTP server
    $mail->From = $email_from;
    $mail->FromName = "SITENAME";
    $mail->AddAddress($email_to);
    $mail->Sender = $email_from;
    $mail->Subject = $email_subject;
    $mail->Body = $email_message;
    $mail->WordWrap = 50;
    ?>

    Try testing that,
    change the $email_to, make it
    $email_to = "you@yoursite.com";
    and change the $email_from, $email_subject, & $email_message to whatever you want.

    Hope this helps

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

    Comment

    • adonairc
      Sergeant

      • Oct 2005
      • 36

      #3
      Re: Help with mail in script

      Thanks budy, that worked, I was using a SMTP plugin with phpmailer maybe that was the problem, now is just sending blank mails, but at least sends something ja ja ja, I think is only thing to find the correct variable.

      Thanks one more time.

      Ado

      Comment

      Working...
      X