PDA

View Full Version : phpmailer



davidjmorin
01-06-2008, 03:17 AM
so i found this script. can anyone help me set it up.

i guess i would just have a form but how do i have it so the form sends using the following script?

the code is located here http://davidmorin.net/mailer/phpmailer.txt

thanks in advance

alexjewell
01-06-2008, 07:55 PM
Tell me what you actually NEED the form to do - will it be dealing with attachments? If it isn't too complicated, like simply sending information, then a much simpler script will work better for you.

davidjmorin
01-08-2008, 04:06 PM
all i want is a form that a user inputs there email and when they hit send it sends them and email with a picture/mp3 in it. so just a basic script. this is what ive come up with so far



<?php
$to = $_POST['email'];
$from = 'test@gmail.com';
$subject = 'Just what you ordered';

$boundary = 'Message-Boundary-' . date('YmdHis');

$headers = 'From: ' . $from . "\n";
$headers .= 'Reply-To: ' . $from . "\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: Multipart/Mixed; boundary=' . $boundary . "\n\n";

$message = '--' . $boundary . "\n";
$message .= 'Content-Transfer-Encoding: 7BIT' . "\n";
$message .= 'Content-Type: text/html; charset=US-ASCII' . "\n\n";

$message .= 'This is the body of the message in HTML.';

$attach = false;
if($attach){
$arrfile = array('file1.jpg', 'file2.jpg'); //// your files here
foreach($arrfile as $f){
$file = $f;
$attach = fopen($file, 'rb');
$data = fread($attach, filesize($file));
fclose($attach);
$data = chunk_split(base64_encode($data));

$ext = strtolower(substr(strrchr($file, '.'), 1));
switch($ext){
case 'pdf': $type = 'application/pdf'; break;
case 'exe': $type = 'application/octet-stream'; break;
case 'zip': $type = 'application/zip'; break;
case 'doc': $type = 'application/msword'; break;
case 'xls': $type = 'application/vnd.ms-excel'; break;
case 'ppt': $type = 'application/vnd.ms-powerpoint'; break;
case 'gif': $type = 'image/gif'; break;
case 'png': $type = 'image/png'; break;
case 'jpe':
case 'jpeg':
case 'jpg': $type = 'image/jpg'; break;
default: $type = 'application/force-download';
}

$message .= "\n\n" . '--' . $boundary . "\n";
$message .= 'Content-Transfer-Encoding: base64' . "\n";
$message .= 'Content-Type: ' . $type . '; name="' . $file . '";' . "\n";
$message .= 'Content-Disposition: inline; filename="' . $file . '"' . "\n\n" . $data;
}
}

mail($to, $subject, $message, $headers);
echo 'E-mail sent!';
?>



and the form:



<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
mail( "someone@example.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
<input type='submit' />
</form>";
}
?>

i have worked really hard and this does not work. Can you test it on your server and see if it does? This is killing me.

Strangeplant
01-09-2008, 07:08 PM
The php mail() function can bog a server down. Why not use swift? See http://www.swiftmailer.org