Skip Navigation

[Resolved] Specific contact form

This thread is resolved. Here is a description of the problem and solution.

Problem: I created a custom type named 'member' with a field named 'mail'. I want to display after the member content (of each member) a form with subject, email of the sender and body inputs. When submitting this form an email will be sent to the member using his e-mail address (field 'mail').

Solution:
- Create a new post type called "Guest Messages" or something similar. Every time someone submits the form on the front-end of the site, a new post will be created in this post type.
- Create a new custom field group that contains all the fields you want to display in the form - subject, sender email, and message. Assign this field group to the Guest Messages post type.
- Create a CRED form that creates new Guest Messages posts. Auto-generate the form code, then insert a hidden generic field. Set the value of that hidden field to be the "mail" field value of the current Member, like this:

<div style="display:none;">[cred_generic_field field='member-email' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[wpv-post-field name='wpcf-mail' id='$current_page']"
}
[/cred_generic_field]</div>

- Insert any other information you want the email to include using Types and Views shortcodes.
- In the CRED notification builder, you select the generic hidden field "member-email" to be used as the "To:" destination email address. You may have to submit the form once on the front-end of the site to see your hidden field appear in the options here.
- Insert this CRED form in the Content Template or Template Layout assigned to the Members post type using the CRED forms shortcodes.

Relevant Documentation:
https://toolset.com/documentation/user-guides/#cred-topics
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 21 replies, has 2 voices.

Last updated by thibaultS 6 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#869471

Yes, it works. (all that for a comma !)

About the mail. It's not possible to have it coming from the "sender" address so the member can easily reply to the e-mail ?

Now i receive a mail from wordpress@avep.salentin.ch

Regards

#869874

You can do that with the cred_mail_header CRED API, but not from wp-admin. Here's a code snippet:

function set_sender_for_notification( $headers, $formid, $postid, $notification_name, $notification_number ) {
    if ($formid==12345) {
        $sender = $_POST['wpcf-sender']
        $myheaders = array( 'Reply-To: ' . $sender, 'From: ' . $sender );
        return array_merge($headers, $myheaders);
    }
    return $headers;
}
add_filter('cred_mail_header', 'set_sender_for_notification', 10, 5);

Replace 12345 with the numeric ID of this CRED form. If this CRED form has more than one notification, you must also target the correct notification with the $notification_name or $notification_number parameters. Those are documented here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_mail_header

Give that a shot and let me know if it is not working as expected.

#870283

So,

Your code is working (retrieve the sender address and change the mail accordingly). Just adding a ;

$sender = $_POST['wpcf-sender'];

But, i misread your recommendation for the previous test. You said NOT to use an email of the same domain as the web site. And i used an email address of the same domain : something@salentin.ch and it's working (for fixed and dynamic address from the mail-member field) but if i choose an address of an other domain (for the fixed address in the notification configuration or dynamically from field 'mail-member', it doesn't work (i checked spam folder, nothing).

DO you know why ?

#873005

If you use the "Send a test email" button to send a test directly to the other domain email address, is it received as expected?

#873357

So,

If i send an email to the same domain (i.e. @salentin.ch), it works but if i send to an other domain (i tried 2 different ones) it fails.

So i think it's a server problem. Can you give me some clue what to check, change on the server configuration to make it works ?

Regards

#873878

I'm not sure, CRED uses the WordPress function wp_mail to send out emails. That function isn't normally restricted by domain in WordPress. It may be something you need to get your host involved with, maybe they a server-level restriction in place for outgoing mail? Maybe they require an SMTP system? Not sure, but if they aren't able to pin something down, I can create a clone of your site and install it on a local environment where I have a working email configuration. If the emails are sent correctly on my clone, then we can assume it's a problem that needs to be addressed by your host, and not a problem that is caused by CRED. Let me know how you would like to proceed.

#875397

My php server was on 5.4, i upgrade it to 7.0 and now it works as desired.

Thanks a lot for the help.

Regards