0

I have an upload script that I have purchased. I need to add some more functionality to it however and my php knowledge is pretty basic. What I need is for an email containing the file location to be sent out via email to a set address. Basically a notification that something has been uploaded.

I have worked out what part of the code these needs to go in, and have got as far as adding this which works perfectly:

// Send Email Notification
       $to = "[email protected]";
       $subject = "A Website User uploaded files";
       $message = "The download link goes here. ";
       $from = "[email protected]";
       $headers = "From:" . $from;
       mail($to,$subject,$message,$headers);

The next line of code in the script outputs the value I want to send in the message of the email like this:

$TMPL['message'] .= '<div class="success">Download: 
<a href="index.php?a=download&q='.$execLastRow[0].'" 
target="_blank">'.$_FILES['fileselect']['name'][$key].'</a></div>';

Obviously this is the wrong syntax but this is the gist of what Im trying to do:

// Send Email Notification
       $to = "[email protected]";
       $subject = "A Website User uploaded files";
       $message = "Download: <a href="index.php?a=download&q='.$execLastRow[0].'" target="_blank">'.$_FILES['fileselect']['name'][$key].'</a>. ";
       $from = "[email protected]";
       $headers = "From:" . $from;
       mail($to,$subject,$message,$headers);

Assistance as always is appreciated!

4 Answers 4

2

Edit

Appending to an existing string add . like .=

$message .= 'Download: <a href="index.php?a=download&q='.$execLastRow[0].'" target="_blank">'.$_FILES['fileselect']['name'][$key].'</a>';

@DevZer0 noticed that you need to add $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; to set the content type to HTML.

Before edit

Because you start the string with " and then href="

So the first " in href is closing your string.

$message = 'Download: <a href="index.php?a=download&q='.$execLastRow[0].'" target="_blank">'.$_FILES['fileselect']['name'][$key].'</a>';

You could compare the row above with yours and check the color syntax.

Sign up to request clarification or add additional context in comments.

4 Comments

That outputs: Download: <a href="index.php?a=download&q=19" target="_blank">dutty-mcmash.jpg</a>. as a single line of text in the email, how would I write it so it keeps the HTML too please?
Sadly thats still outputting the same thing in the body of the email
@WebblyBrown you need to set content-type to text/html. in the email header
Ahh ok so I need to add a MIME type for HTML to the header, thats working guys thanks
2

Your problem is to put variables in a string right?

  $message = 'Variable1: ' . $var1 . ', Variable2: ' . $var2 . ', Variable3: ' . $var3;

Comments

1

Change -

$message = "Download: <a href="index.php?a=download&q='.$execLastRow[0].'" target="_blank">'.$_FILES['fileselect']['name'][$key].'</a>. ";

To

$message = 'Download: <a href="index.php?a=download&q='.$execLastRow[0].'" target="_blank">'.$_FILES['fileselect']['name'][$key].'</a>.';

1 Comment

That outputs: Download: <a href="index.php?a=download&q=19" target="_blank">dutty-mcmash.jpg</a>. as a single line of text in the email, how would I write it so it keeps the HTML too please?
0

You could assign text like this.

$message = <<<HTML
"Download: <a href="index.php?a=download&q={$execLastRow[0]}" target="_blank">{$_FILES['fileselect']['name'][$key]}</a>. ";
HTML;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.