Skip to content
Advertisement

PHP issue about sending mail message

I am having an issue when sending e-mail using php code. I have a form which sends an attachment to a folder and the name of the attachment to the database, in order to then send the link of the file inside the message.

The problem is that the file and all the rest go the way it should but I can’t seem to create the link.

Here is the code:

$email = $_REQUEST['email'] ;
$to = $_REQUEST['to'] ;
$subject = $_REQUEST['subject'] ;
$message = ''.$_REQUEST['message'].'<a href="http://lamyse.net/images/'.$file_name.'"> download</a>';



$sql="SELECT file  FROM login_admin WHERE user_name='dori'";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result)) {


$file_name = $row['file'];}
    
  
mail($to, $subject, $message, "From:" . $email);
 
$photo =$_FILES['file']['name'];

$target = "images/";
$target = $target . basename( $_FILES['file']['name']);

Thanks!

Advertisement

Answer

You don’t get $file_name until a few lines after you try to use it. Quick fix would be to move

$message = ''.$_REQUEST['message'].'<a href="http://lamyse.net/images/'.$file_name.'"> download</a>'; 

below your while loop.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement