Re: Problem with attaching file (from a form) to email in PHP [message #172781 is a reply to message #172780] |
Tue, 01 March 2011 01:07 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 2/28/2011 7:58 PM, Cameleon wrote:
> Thanks Jerry... can I use variables, like I did below... it keeps
> telling me invalid address??
>
>
>
> =======
>
> // MAIL SUBJECT
> $subject = $_POST['Sujet'] . " from site xyz";
> $subject = str_replace("\'", "'", $subject);
>
>
> // MAIL ADDRESSES
>
> $nom = str_replace("'", "''", $_POST['Nom']);
> $NameFrom = $nom;
> $EmailFrom = "<" . $_POST['Email'] .">";
>
> $NameTo = "Test User";
> $EmailTo = "<Tests(at)xyz(dot)com>";
>
>
>
> ....
>
>
>
> require_once '../class.phpmailer.php';
>
> $mail = new PHPMailer(true);
>
>
>
> try {
> $mail->AddReplyTo($EmailFrom, $NameFrom);
> $mail->AddAddress($EmailTo, $NameTo);
> $mail->SetFrom($EmailFrom, $NameFrom);
> $mail->AddReplyTo($EmailFrom, $NameFrom);
> $mail->Subject = $subject;
> $mail->AltBody = $message;
> $mail->MsgHTML(file_get_contents('message.html'));
> $mail->AddAttachment($UploadedFile_name);
> $mail->Send();
> echo "Message Sent OK<p></p>\n";
> }
>
Among other things, you need to do a LOT more sanitizing of your $_POST
fields. NEVER trust input from the user!
And look at the examples again. You do not place <..> around the address.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|