PHP - Attach image to mail() function?

Hello,

Sorry im a newbie to PHP…

My script below takes user input from my html form and emails the results to me…

On my form i have an upload form field, and wish for the end user to be able to upload an image which i want either attached to, or preferabally to be part of the body on the email message!

(As you can se i have managed to get the PHP file to take the uploaded image and place it in a directory…my problem is…how to send the mail with that picture attached or part of the email body?)


<?php
  $file_dir = $_SERVER['DOCUMENT_ROOT'] . '/terry/uploads/';
  $name = $_REQUEST['name'] ;
  $phone = $_REQUEST['telephone'] ;
  
  foreach($_FILES as $file_name => $file_array) {
 if (is_uploaded_file($file_array["tmp_name"])) {
  move_uploaded_file($file_array["tmp_name"], "$file_dir/".$file_array["name"]) or die ("Couldn't copy");
 }
  }
  
  $string = "T-Shirt order form....


";
  $string .= "Name:                        ".$name."
";
  $string .= "Telephone Number:            ".$phone."
";
  $string .= "T-Shirt Design"."

";
  
 mail("root@thanweb.co.uk", "Website - T-Shirt Order", $string, "From: root@thanweb.co.uk", "-froot@thanweb.co.uk"); 
 header( "Location: http://www.thanweb.co.uk/thankyou.htm" );
?>

Add the image URL into the message itself?


  $string = "T-Shirt order form....


";
  $string .= "Name:                        ".$name."
";
  $string .= "Telephone Number:            ".$phone."
";
  $string .= "T-Shirt Design"."

";
  $string. = "<img src=\"imageURL\" >";


Thank you ahmednuamen i will try that!

Project 107…

The image is going to be one that will be uploaded by the end user so i will not know the name of the image to be displayed…hence why im asking here how to extract the most recently submittted image other than simply displaying a static image on the server if you see what i mean.

Thank you anyhow.

:slight_smile: