Member 13165645 Ответов: 1

Я хочу попробовать отправить электронное письмо с вложением в PHP


<?php
if(isset($_POST['submit']))
{
	$phone= $_POST['phone'];
        $email = $_POST['email'];
	$subject = $_POST['subject'];
        $deadline = $_POST['deadline'];
        $file = $_POST['file'];
        $comments = $_POST['comments'];
        $to = $email;
	$headers = "FROM:<parveen0055@gmail.com>";
	$message = "Phone: $phone\n\n Email: $email \n\n Subject: $subject \n\n  Deadline: $deadline \n\n Message: 
        $comments";

	if(mail($to, $subject, $message, $headers, $attachment))
	{
		echo "Email Sent";
	}
	else
	{
		echo "Error Sending Email";
	}
}
?>





<title>sending mail



<p>Phone<br>
</p>
<p>Email<br>
</p>
<p>Subject<br>
</p>
<p>Deadline<br>
</p>
<p>Attachment<br>
</p>
<p>Comments<br>
</p>
<p></p>




What I have tried:

i am trying to attach any type of file to send mail using php but file doesn't included/

1 Ответов

Рейтинг:
1

Wessel Beulink

используйте скрипт phpmailer: [PHPMailer] функция php. mail () не очень хороша.

Документация находится в проекте github, и ее очень ясно использовать.

$email = new PHPMailer();
$email->From      = 'you@example.com';
$email->FromName  = 'Your Name';
$email->Subject   = 'Message Subject';
$email->Body      = $bodytext;
$email->AddAddress( 'destinationaddress@example.com' );

$file_to_attach = 'PATH_OF_YOUR_FILE_HERE';

$email->AddAttachment( $file_to_attach , 'NameOfFile.pdf' );

return $email->Send();