2

So I have a contact form set up in Craft using the Contact Form plugin. I have it rigged up with Mandrill as the SMTP provider and unfortunately with the notifications, the from email address is getting stripped out of the headers by Mandrill. So there's no way to determine who the email came from in order to reply to that person.

So my question is - is there a way to set the replyto to the fromEmail OR is there a way to output the from: email address in the resulting notification message?

Many thanks in advance from me and the client dealing with it!

Cheers, J

3 Answers 3

2

Not without hacking (boo!) or forking (yay!) the plugin.

Currently, the fromEmail is being set from the email address set in the plugin's setting.

$email->fromEmail = $emailSettings['emailAddress'];

And the replyTo is being set to the email that was supplied on the front-end contact form.

$email->replyTo   = $message->fromEmail;

This is done because some email servers will see that the from address is different than the domain the email originated on and wrongly mark it as SPAM.

You'd adjust those however you need.

If you want to output the email in the message body, you'd just need to add it to the $message->message property in the controller.

Alternatively, you can use a more robust form building solution.

2

I've used JS to copy the form input content into hidden fields that gets added to the message in this way...

<input id="fromName" type="text" name="fromName" value="{% if message is defined %}{{ message.fromName }}{% endif %}">
<input type="hidden" id="fullName" name="message[Full Name]" class="fullName">

<input id="fromEmail" type="email" name="fromEmail" value="{% if message is defined %}{{ message.fromEmail }}{% endif %}">
<input type="hidden" id="emailAddress" name="message[Email Address]" class="emailAddress">

<input type="hidden" id="currentDate" name="message[Date Submitted]" class="currentDate" value="{{ now|date("F j, Y - g:i a") }}">

Then I add something like this on submit:

$('#fromName').bind('keypress keyup blur', function() {
  $('#fullName').val($(this).val());
});

To get the info copied to the corresponding fields. This helps me get a nice emailed message with all the data I want:

Full Name: jane Doe
Email Address: [email protected]
Phone: 5551234567
Message: TESTING ONLY
Date Submitted: December 17, 2015 - 12:02 pm

This solution gets the info needed into the notification, but doesn't help with headers.

1

I'm generally including the email in the message body in every project by tweaking the plugin like so...

Open controllers/ContactFormController.php and look for:

$compiledMessage = '';

and then, below it, add something like this:

$compiledMessage .= "Please reply to: ";
$compiledMessage .= $message->fromEmail;
$compiledMessage .= "\n\n";

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.