Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    PHP form details not sent to email

    Hello

    I hav these two files on a Linux server which insists on smtp authentication. I get a 'your message has been sent' message, but the email never arrives.

    This is the HTML form:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Form2Mail</title>
    </head>
    <body bgcolor="#ffffff" text="#000000">
    <div>
    <center>
    <form method="post" enctype="multipart/form-data" name="send" action="formprocess.php">
    <table border="0" bgcolor="#ececec" cellspacing="5">
    <tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
    <tr><td>Email address</td><td><input type="text" size="30" name="emailaddr"></td></tr>
    <tr><td>Message</td><td><textarea name="message" rows="6" cols="30"></textarea></td></tr>
    <tr><td>Attachment</td><td><input type="file" name="attachment" size="50" /><br /></td></tr>
    <tr><td>&nbsp;</td><td><input type="submit" value="Send"></td></tr>
    </table>
    </form>
    </center>
    </div>
    </body>
    </html>
    And this is the PHP script behind it:

    Code:
    <?php 
    $fileatt = ""; // Path to the file 
    $fileatt_type = "application/octet-stream"; // File Type 
    $fileatt_name = ""; // Filename that will be used for the file as the attachment 
    $email_from = ""; // Who the email is from 
    $email_subject = ""; // The Subject of the email 
    $email_txt = ""; // Message that the email has in it 
    $email_to = "myEmail@yahoo.com"; // Who the email is to 
    $headers = "From: ".$email_from; 
    $file = fopen($fileatt,'rb'); 
    $data = fread($file,filesize($fileatt)); 
    fclose($file); 
    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    $headers .= "\nMIME-Version: 1.0\n" . 
    "Content-Type: multipart/mixed;\n" . 
    " boundary=\"{$mime_boundary}\""; 
    $email_message .= "This is a multi-part message in MIME format.\n\n" . 
    "--{$mime_boundary}\n" . 
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
    "Content-Transfer-Encoding: 7bit\n\n" . 
    $email_message . "\n\n"; 
    $data = chunk_split(base64_encode($data)); 
    $email_message .= "--{$mime_boundary}\n" . 
    "Content-Type: {$fileatt_type};\n" . 
    " name=\"{$fileatt_name}\"\n" . 
    //"Content-Disposition: attachment;\n" . 
    //" filename=\"{$fileatt_name}\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . 
    $data . "\n\n" . 
    "--{$mime_boundary}--\n"; 
    $ok = @mail($email_to, $email_subject, $email_message, $headers); 
    if($ok) { 
    echo "The file was successfully sent!"; 
    } else { 
    die("Sorry but the email could not be sent. Please go back and try again!"); 
    } 
    
    $host = "smtp.mySite.com";
            $username = "info@mySite.com";
            $password = "myPassword";
    
    ?>
    Any help appreciated.

    Thanks.

    Steve

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    $ok = @mail($email_to, $email_subject, $email_message, $headers);
    Try removing the error suppression operator (@) from there.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Thanks for your reply.

    I have removed the @ and I get a 'The file was successfully sent!' message but, again, the email is not arriving.

    Does this:

    Code:
    $host = "smtp.mySite.com";
            $username = "info@mySite.com";
            $password = "myPassword";
    need to be in any particular place in the script or can I leave it where I wish?

    Thanks

    Steve

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That host/username/password combo isn't doing anything down there, and it won't help if you move it. Your form handler is just using PHP's mail() function and that doesn't handle authentication.

    Many people have been recommending the phpmailer package for something like that. It's a good mailer with ample documentation and examples.
    Are you a Help Vampire?

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello tomws

    Oh, right. I didn't know that, thanks.

    So I have to use delete the smtp details in my original PHP script and use the following, presumably called class.phpmail.php?

    Code:
    require_once('../class.phpmailer.php'); 
    //include("class.smtp.php"); // optional 
     
    $mail             = new PHPMailer(); 
    $body             = file_get_contents('contents.html'); 
    $body             = eregi_replace("[\]",'',$body); 
    $mail->IsSMTP(); // telling the class to use SMTP 
    $mail->Host       = "mail.yourdomain.com"; // SMTP server 
    $mail->SMTPDebug  = 2;   // enables SMTP debug information (for testing) 
    $mail->SMTPAuth   = true; // enable SMTP authentication 
    $mail->Host       = "smtp.mySite.com"; // sets the SMTP server 
    $mail->Port       = 26;  // set the SMTP port for the GMAIL server 
    $mail->Username   = "info@mySite"; // SMTP account username 
    $mail->Password   = "myPassword"; // SMTP account password 
    $mail->SetFrom('info@mySite.com', 'First Last'); 
    $mail->AddReplyTo("info@mySite.com","First Last"); 
    $mail->Subject    = "my Subject"; 
    $mail->AltBody    = "Use an HTML compatible email viewer!"; // optional
    $mail->MsgHTML($body); 
    $address = "whoto@otherdomain.com"; 
    $mail->AddAddress($address, "John Doe"); 
    $mail->AddAttachment("images/phpmailer.gif");      // attachment 
    $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment 
    if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    } else { 
      
    echo "Message sent!"; 
    }
    I am not quite sure what it is expecting here:

    Code:
    $address = "whoto@otherdomain.com"; 
    $mail->AddAddress($address, "John Doe");
    and how would I reference this class.phpmail.php in my original script?

    Thanks.

    Steve

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Read the documentation and the readme.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    The documentation, tutorials, and examples (links provided earlier) should provide enough information to get you set up with phpmailer.

    That code pasted from one of the examples is not class.phpmailer.php. That filename is the class file to include/require from the phpmailer package. The example code is for replacing the mail() function - this one specifically appears to pull the message body from a file, so it's not exactly the one you want. Modify as needed.

    The addAddress method does just that: it adds an address (a To address), as described in the documentation.
    Are you a Help Vampire?


  •  

    Posting Permissions

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