Użyłem phpmailer, załączniki są dostarczane. W jaki sposób przerobić kod żeby cała wiadomość razem z załącznikiem była wysyłana przez phpmailer. W tej chwili otrzymuję dwie wiadomości jedna z załącznikiem, druga z treścią formularza jak to połączyć (IMG:
style_emoticons/default/questionmark.gif)
<input class="i2" type="submit" value="wyślij" style="width: 80px; height: 35px">
<input type="file" name='myFile'> <input type="hidden" name="MAX_FILE_SIZE" value="5200000" />
<?php
function died($error) {
echo $error."<br /><br />";
}
if(isset($_POST['email'])) { $email = $_POST['email'];
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "aaa@wp.pl";
$email_subject = "Your email subject line";
require_once($_SERVER['DOCUMENT_ROOT'].'/b/lib/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->PluginDir = "/b/";
$mail->From = "aaa@wp.pl"; //adres naszego konta
$mail->FromName = "naglowek wiadomosci";//nagłówek From
$mail->Host = "smtp.wp.pl";//adres serwera SMTP
$mail->Mailer = "smtp";
$mail->Username = "aaa@wp.pl";//nazwa użytkownika
$mail->Password = "xxxxx";//nasze hasło do konta SMTP
$mail->SMTPAuth = true;
$mail->SetLanguage("pl", "./b/lib/phpmailer/language/");
$mail -> SMTPSecure = true;
$mail -> Port = 465;
$mail->Subject = "Mail testowy";//temat maila
// w zmienną $text_body wpisujemy treść maila
$text_body = "Cześć, chyba phpMailer działa \n\n";
$text_body .= "Na zawsze Twój, \n";
$text_body .= "PHPMailer";
$mail->Body = $text_body;
// adresatów dodajemy poprzez metode 'AddAddress'
$mail->AddAddress("aaa@wp.pl","Kolega");
$myFile = $_FILES['myFile'];
$save_path = dirname( __FILE__ ) . "/" . $myFile['name'];
copy( $myFile['tmp_name'], $save_path );
$mail->AddAttachment(@$_FILES['myFile']['name'],@$_FILES['myFile']['name']);
if(!$mail->Send())
echo "There has been a mail error <br>"; echo $mail->ErrorInfo."<br>";
// Clear all addresses and attachments
$mail->ClearAddresses();
$mail->ClearAttachments();
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])){
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
else
{
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$error_message .= '<span style="font-size: 10px; color:#FF0000;">The Email Address you entered does not appear to be valid.<br /></span> ';
}
$string_exp = "/^[A-Za-z .'-]+$/";
$error_message .= '<span style="font-size: 10px; color:#FF0000;">The First Name you entered does not appear to be valid.<br /></span> ';
}
$error_message .='<span style="font-size: 10px; color:#FF0000;">The Last Name you entered does not appear to be valid.<br /></span> ';
}
$error_message .= '<span style="font-size: 10px; color:#FF0000;">The Comments you entered do not appear to be valid.<br /></span> ';
}
if(strlen($error_message) > 0
) {
died($error_message);
}
else
{
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "File: ".clean_string($_FILES['myFile']['name'])."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
mail($email_to, $email_subject, $email_message, $headers);
echo '<span style="color:#009900; font-size: 10px;">Thank you for contacting us. We will be in touch with you very soon.</span> '; }
}
?>
<!-- include your own success html here -->
<?php
}
?>