This script works fine, but there's a part I'm not sure if there's an easier / better way to do it. The part I'm talking about is commented in the script. Also any general advice on improvements if there are any to be would be cool.
<?php
if (isset($_POST['submit'])) {
//Variables
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$id = rand(1000, 9999);
//Headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: email@email.co.uk' . "\r\n";
$headers .= 'Cc: email@email.co.uk' . "\r\n";
//Email Information
$to = $email;
$subject = 'Project Information';
//Email Body
$message = '<html><body>';
$message .= '<h1>Message</h1>';
$message .= '<h1>Quote ID</h1>';
$message .= '<p>' . $id . '</p>';
if (!empty($name)) {
$message .= '<h1>Name</h1>';
$message .= '<p>' . $name . '</p>';
}
$message .= '<h1>Message</h1>';
$message .= '<a href="http://www.domain.com/clients/' . $name . '.php">Link</a>';
$message .= '</body></html>';
//Send Email
if (mail($to, $subject, $message, $headers)) {
echo 'Message Sent';
} else {
echo 'Message Failed';
}
//Unsure about this
//Here a php page is generated by the main php
//I've done it like the message above but I'm unsure if this is correct?
$request = '<?php ';
$request .= '$headers = "From: email@email.co.uk"."\r\n";';
$request .= '$to = "email@email.co.uk";';
$request .= '$subject = "Invoice Request";';
$request .= '$message = "' . $name . ' is requesting ' . $id . ' quote";';
$request .= 'mail($to, $subject, $message, $headers);';
$request .= 'unlink(__FILE__)';
$request .= ' ?>';
$request .= '<h1>Invoice Being sent asap</h1>';
//Write the above php to a file
$myfile = fopen('clients/' . $name . '.php', 'w');
fwrite($myfile, $request);
fclose($myfile);
}
?>