Hello all,
I’m trying to send an email from a contact form but I can’t get it to work properly.
Firstly, the line breaks aren’t showing up on the email when I get it and secondly I can’t set additional headers to set the from address, if I try to set them the email doesn’t send.
This is my code
[php]
if (!empty($_POST[‘name’]) && !empty($_POST[‘email’]) && !empty($_POST[‘message’])) {
$name = trim($_POST[‘name’]);
$company = trim($_POST[‘company’]);
$phone = trim($_POST[‘phone’]);
$email = trim($_POST[‘email’]);
$event_value = trim($_POST[‘event-calendar’]);
$event_type = trim($_POST[‘event-type’]);
$message = trim($_POST[‘message’]);
} else {
$error_message = ‘Please fill in all required fields’;
return $error_message;
}
$email_content = 'From: ’ . $name . ‘\n\n’.
'Company: ’ . $company . ‘\n\n’.
'Phone: ’ . $phone . ‘\n\n’.
'Email: ’ . $email . ‘\n\n’.
'Event info: ’ . $event_value . ’ ’ . $event_type . ‘\n\n’.
'Message: ’ . $message;
if (!mail(‘[email protected]’,‘test message’,$email_content)) {
$error_message = ‘Error sending email’;
return $error_message;
} else {
header("Location: " . BASE_URL . “contact?success=true”);
exit;
}
[/php]
Now it works if I don’t put additional headers on the email, but the line breaks aren’t working and I need to set the From header otherwise it just shows up as the server name or whatever it is. If I put 'From: ’ . $email after the $email_content variable then it just comes up with ‘Error sending email’ when I try to send it.
Any advice?
Thanks,
Adam