Jump to content

[SOLVED] Insert image into PHP generated email


Iron Bridge

Recommended Posts

I feel like a nuisance for asking such simple questions. I have a flash site for my upcoming wedding and within the site I have a guest form to collect addresses of our guests (for traditional invitations).  The variables are sent via actionscript to a PHP script which then inserts the information into an SQL DB and emails both myself and the guest.  In the email to the guest I would like to insert an animated .gif file as a signature.  I know this is really simple yet I can't seem to get it to work.  I have looked at the PHP manual and spent a good amount of time browsing forums and tutorials but to no avail.  It comes down to my lack of knowledge of PHP syntax.  I have pasted a  sample of the code I am using with both email functions.  Hopefully somebody can point out my error.  I appreciate the help.  As somone with essentially no PHP knowledge this forum has helped me tremendously.  I find myself spending much more time in flash forums to help others as this forum has helped me.  Anyways, I am off to go and click some advertisements.

 

$thanks = "Dear " . $_POST['name'].",";
$thanks .= "\n\n";
$thanks .= "Thank you for visiting our website.........";
$thanks .= "\n\n";
$thanks .= "Sincerely,";
$thanks .= "\n\n";
$thanks .= $html;
$thanks .= "\n\n";
$thanks .= "Alene and Sage";

$ouremail = "From: Alene and Sage <[email protected]>";
$html = '<img src="images/ansSignature.gif">';

mail($sendTo, $subject, $message, $headers);
mail ($_POST["email"], "Thank you for adding your address", $thanks, $ouremail);

place your $html variable over your $thanks variables and place the $html in $thanks in quotes, like this:

 

$html = '<img src="images/ansSignature.gif">';

$thanks = "Dear " . $_POST['name'].",";
$thanks .= "\n\n";
$thanks .= "Thank you for visiting our website.........";
$thanks .= "\n\n";
$thanks .= "Sincerely,";
$thanks .= "\n\n";
$thanks .= $html;
$thanks .= "\n\n";
$thanks .= "Alene and Sage";

$ouremail = "From: Alene and Sage <[email protected]>";

mail($sendTo, $subject, $message, $headers);
mail ($_POST["email"], "Thank you for adding your address", $thanks, $ouremail);

Thanks for the timely reply. When I do this (place $html =... earlier in the script and $thanks .= "$html";) the email displays:

 

Dear ______,

 

Thank you for visiting our website..........

 

Sincerely,

 

<img src="images/ansSignature.gif">

 

Alene and Sage

 

The actual image does not who up.  Any ideas as to why?

Enclose your message in HTML by adding:

 

$thanks = "<html><body>";

 

to the beginning (before anything else), and:

 

$thanks .= "</body></html>";

 

to the end, before you send the message. If it still doesn't work then the email client probably doesn't read HTML emails.

So, I have placed:

 

$thanks = "<html><body>"; 
$thanks .= ....
$thanks .= "</body></html>;

$ouremail .= "Content-type: text/html";

 

and I am still not getting the image.  I know my mail client (Apple Mail) supports HTML email since I have made and received HTML emails before.  Any more ideas?

You guys are absolutely awesome. I finally got it woked out.  I just had to change my

 

$thanks .= "\n\n";

 

to

 

$thanks .= "<br></br>; 

 

An example of the final code that I am using is listed below.  This code delivers variables from a form via actionscrript 2.0 to a PHP script.  The variables are then emailed to both me and the sender.  I have designed the script to also implement the variables into an SQL DB but have left that part out.  I hope this helps somebody in the future.

 

$sendTo = "me@myemailaddress";
$subject = "whatever I would like it to be";

//All of the variable here are defined in flash through the variables dialog and not the instance name
//I have found that using instance names produces less reliable results
$headers = "From: " . $_POST["name"] ." <" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];

// now add the content of the flash message to a body variable.  This creates a plain text email message
$message = $_POST["message"];
$message .= "\n\n---------------------------\n";
$message .= "Mail sent by: " . $_POST['name'] . " <" . $_POST['email']  . ">\n";
$message .= "Our Address is: " . $_POST['address'] . " " . $_POST['city']  . "\n";

//HTML email with animated gif for signature
$thanks = "<html><body>";
$thanks .= "Dear " . $_POST['name'].",";
$thanks .= "<br></br>";
$thanks .= "Thank you for visiting our website.........";
$thanks .= "<br></br>";
$thanks .= "Sincerely,";
$thanks .= "<br></br>";
$thanks .= '<img src="http://www.OurURL/images/ourGIF.gif"/>';
$thanks .= "<br></br>";
$thanks .= "Alene and Sage";
$thanks .= "</body></html>";

$ouremail = "From: Us <[email protected]>";
$ouremail .= "\r\nContent-type: text/html";

mail($sendTo, $subject, $message, $headers);
mail ($_POST["email"], "Thank you for adding your address", $thanks, $ouremail);

 

Of course you could also add additional headers to the $thanks variable if you would like.  I would like to tip my hat to the people who assisted me with this.  I really appreciate the help.

 

Sage

http://www.aleneandsage.us

http://www.ironbridge.vox.com

http://www.sensationalsmyles.com

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.