PHP - send email not working

Discussion in 'PHP' started by CuBz, Aug 13, 2010.

  1. #1
    I have a page that send users their password but nobody recieves the emails.

    Can somebody tell me why please, because I can't see anything wrong

    
    $subject = "Password Retrieval - $username"; 
    $message = "
        Dear $username, 
    
        Your password is $password
      
         
        Enjoy
    
        Admins
    
         
        This is an automated response, please do not reply!"; 
         
    if (mail($email, $subject, $message, "From:admin@mywebsite.com")){
    die("<b>An email has been sent with your password!<br>Make sure you check your Junk Folder!</b>"); 
    
    }
    PHP:
    Thanks
     
    CuBz, Aug 13, 2010 IP
  2. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2

      
          <?php
        require_once "Mail.php";
        $name=$_POST['name'];
        $address= $_POST['address'];
        $email=$_POST['email'];
    	$from = $name;
        $to = "write email id where you want to send";
        $sub=$_POST[sub];
        $msg =$name."\n".$_POST['msg']."\n";
    
        $host = "localhost";
        $username = "your company mail id";
        $password = "password";
    
        $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>");
         }
        ?>
    Code (markup):
    Use the above code i u r sending mail to yahoo,gmail etc and use mail() for mailing to your server email id
     
    Om ji Kesharwani, Aug 13, 2010 IP
  3. longvnit

    longvnit Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Maybe mail() function in your server disabled. U should be using PHPMailer which good library for send mail function.
     
    longvnit, Aug 18, 2010 IP
  4. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #4
    Whatever "Mail.php" is, he doesn't have it. Anyway, the only thing I see that could be wrong is that you don't define the $email variable anywhere.
     
    Thorlax402, Aug 18, 2010 IP