I am fairly new to php, but learning fast.
I have a mysql database that is storing information for a client that they input backend, then the customer views all the information as it is listed from the database, and can choose to apply to a specific one. Each one is sent to a different email as they chose it depending which employee is hiring.
if in my apply.php file which contains the mail function i set
$to = 'email@email.com'
my mail function works fine, but I am trying to set $to to equal a email address that is being passed via a url from the previous page.
<FORM METHOD="POST" ACTION="javascript:popUp('apply.php?sub=$row[0]&remail=$row[4]')" target="_blank">
so I get something like /apply.php?sub=NewEmployee&remail=email@email.com
I am then calling down the variables in the apply.php form.
$to does obtain the email address from the variable, but when in this form it does not work in the mail function and does not send the email, but when I change $to = 'email@email.com' it works.
I am sure i am missing something simple here, and help?
thanks in advance!
<?php
$sub = $_GET['sub'];
$sub2 = urlencode($sub);
$to = $_GET['remail'];
if (isset($_POST['email']) &&
isset($_POST['fname']) &&
isset($_POST['lname']) &&
isset($_POST['job']) &&
isset($_POST['addition']))
{
$replyTo = $_POST['email'];
$from = $_POST['fname'] . " " . $_POST['lname'];
$job = $_POST['job'];
$subject = "Application for : " . $job;
$message = stripslashes("Name : " . $from . "\r\n\r\n" . "Email : " . $_POST['email'] . "\r\n\r\n" . "Job : " . $job . "\r\n\r\n" . "Additional Information : " . $_POST['addition'] . "\r\n\r\n");
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: " . $from . "\r\nReply-To: " . $replyTo;
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
"boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\r\n\r\n" .
"--{$mime_boundary}\r\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
$message . "\r\n\r\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\r\n" .
"Content-Type: {$fileatt_type};\r\n" .
" name=\"{$fileatt_name}\"\r\n" .
"Content-Disposition: attachment;\r\n" .
"filename=\"{$fileatt_name}\"\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n" .
$data . "\r\n\r\n" .
"--{$mime_boundary}--\r\n";
}
// Send the message
$ok = @mail($to, $subject, $message, $headers);
$theResults = <<<EOD
<html>
<head>
<title>The test Page </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>
<div>
<div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
die();
}
echo <<<_END
<form action="apply.php" method="post" enctype="multipart/form-data"><pre>
<img src='nason.jpg' width='350' height='75' />
Job Applying for :<b> $sub </b><hr size="1" width=400 align="left" color="#828282">
Sending Resume To : $to
First Name : <input type="text" name="fname" />
Last Name : <input type="text" name="lname" />
Email : <input type="text" name="email" />
Upload Resume : <input type="file" name="fileatt"/>
(.pdf or .doc)
Additional Information :
<textarea name="addition" rows="15" cols="50" ></textarea>
<input type="hidden" name="job" value=$sub2 />
<input type="submit" value="Submit Resume" />
</pre></form>
_END;
?>