Jump to content

php email problems


contra10

Recommended Posts

I'm having trouble with emails and php when it sends to a hotmail account everything shows but in gmail or yahoo accout it shows a download link for a no name file, the actual writing doesn't show

 

<?php
$to = ($email);
$subject = "Verification";
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
$from = "[email protected]";
$headers = "From: $from";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
//define the body of the message.
ob_start(); //Turn on output buffering
?>

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit


<div style="width:800px; 
height:400px; 
border:4px dashed grey; 
">
<table bgcolor="black" width="800" >

<tr><td>
<img src="http://www.url.com/images/logo.png"/><br><br><font size="12" color="white">You have sucessfully become a member</font><br>

<?php
echo"<p align='center'>";
echo"<table background='#6D6D6D' width='700' height='250'>";
echo "<tr><td><b><font color='white'>Dear, $usere <br><br> 
To complete your activation please click on the \"Verify\" link below.";
echo "<b>To contine to verify your account please follow the link </b><a href='http://www.url.com/verify.php?v=$usere' target='_blank'><font color='red'>Verify Account</font></a>";
echo"</font></td></tr>";
echo "</table>";
echo"</p>";
?>
 </td></tr>
<tr><td align="center"><font size="1" color="white">Copyright 2009</font></td></tr>
</table>
</div>

--PHP-alt-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( "$to", $subject, $message, $headers );

?>

Link to comment
https://forums.phpfreaks.com/topic/176358-php-email-problems/
Share on other sites

Go to my sig link it all about headers pal.

 

add this as a extras header.

<?php
$headers = 
        'X-Mailer: PHP/' . phpversion() . "\r\n" .
        "MIME-Version: 1.0\r\n" .
        "Content-Type: text/html; charset=utf-8\r\n" .
        "Content-Transfer-Encoding: 8bit\r\n\r\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/176358-php-email-problems/#findComment-930429
Share on other sites

Go to my sig link it all about headers pal.

 

add this as a extras header.

<?php
$headers = 
        'X-Mailer: PHP/' . phpversion() . "\r\n" .
        "MIME-Version: 1.0\r\n" .
        "Content-Type: text/html; charset=utf-8\r\n" .
        "Content-Transfer-Encoding: 8bit\r\n\r\n";
?>

 

 

That doesn't help with multipart headers at all.

Link to comment
https://forums.phpfreaks.com/topic/176358-php-email-problems/#findComment-930432
Share on other sites

 

 

This works been told

<?php
        $from = "From: <[email protected]>";  
    
        $fileatt = "PDF/";
	$fileatt .= $filename;
        $fileatttype = "application/pdf"; 
	$fileattname .= $filename;
    
        $headers = "From: $from";

	$messageletter = "what ever text you would like in here. It can be huge and use \n to start a new line within the email";
        
        $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}\"";
    
        $message = "This is a multi-part message in MIME format.\n\n" . 
                "--{$mime_boundary}\n" . 
                "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
                "Content-Transfer-Encoding: 7bit\n\n" . 
                $messageletter . "\n\n";
    
        $data = chunk_split( base64_encode( $data ) );
                 
        $message .= "--{$mime_boundary}\n" . 
                 "Content-Type: {$fileatttype};\n" . 
                 " name=\"{$fileattname}\"\n" . 
                 "Content-Disposition: attachment;\n" . 
                 " filename=\"{$fileattname}\"\n" . 
                 "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                 "--{$mime_boundary}--\n";

        if( mail( $to, $subject, $message, $headers ) ) {
         
            echo "<p>The email was sent.</p>"; 
         
        }
        else { 
        
            echo "<p>There was an error sending the mail.</p>"; 
         
        }
?>

Link to comment
https://forums.phpfreaks.com/topic/176358-php-email-problems/#findComment-930440
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.