Send Image Url with Form Submit

Send Image Url with Form Submit

I have contact form that sends an image div in a client mail

<form name="form" method="post" action="mail.php" id="myForm"> 
</form>

The form is submitted by an input type submit

<input name="submit" type="submit" value="Submit" id="capture" />

My php for sending email is

<?php
include("auth.php");
//message
$message = $_POST['msg'];
$username =$_REQUEST['username'];
$surname =$_REQUEST['surname'];
$name= $_REQUEST['name'];
$filename = md5(uniqid(rand(), true));
$imageurl  = '
//mail body - image position, background, font color, font size...

$body = "Dear $surname  $name
Thank you for your Pre-registration for Global.
Please print the attached e-ticket with your personal barcode and bring it to the reception of the exhibition.
This barcode includes data about you which is required during registration. Having this barcode will considerably speed up the registration process
Organizing committee.\n".



$body = "Print e-ticket
              $imageurl.\n".





//to send HTML mail, the Content-type header must be set:
$headers='MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html;charset=iso-8859-1' . "\r\n";
$headers .= 'From: < . "\r\n";
$to = $_POST['mail'];
$subject = "EXPRESS REGISTRATION (Global)";
//mail function
$email = mail($to, $subject, $body, $headers);
if(!$email) { 
echo "Error sending email"; 
} else {
echo "Your email was sent successfully.";
}
?>

Then i have an ajax function for saving an dynamically created image on the server

<script>
 $("#capture").click(function() { 
html2canvas([document.getElementById('printableArea')], {
    onrendered: function (canvas) {
        var imagedata = canvas.toDataURL('image/png');
        var imgdata = imagedata.replace(/^data:image\/(png|jpg);base64,/, "");
        //ajax call to save image inside folder
        $.ajax({
            url: 'save_image.php',
            data: {
                   imgdata:imgdata
                   },
            type: 'post',
            success: function (response) {   
               console.log(response);
               $('#image_id img').attr('src', response);
            }
        });
    }
})
 });
</script>

My php file for saving image on the server

<?php
$imagedata = base64_decode($_POST['imgdata']);
$filename = md5(uniqid(rand(), true));
//path where you want to upload image
$file = '/home/a7784524/public_html/barcodeimage/'.$filename.'.png';
$imageurl  = '
file_put_contents($file,$imagedata);
echo $imageurl;

My problem is that i want to send imageurl to email client on form submit Thank you

1 Answer

$imageurl  = '

Here you used string concatenation.

But here you didn't:

$body = "Print e-ticket   $imageurl.\n".

You just need to do the same thing you did when you created the $imageurl with a random file name :)

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.