联系表格IP地址

I have a contact form, the entire markup for which (other than the javascript) can be found here. The form sends an email with the information input by the user to whichever email is defined under to_email in an options panel.

I am using this form in WordPress and would like to have the IP address of the person filling out the form attached to the message. I tried incorporating code from this post but I'm a newbie to PHP and can't seem to incorporate it correctly (to actually send it with the rest of the message).

If anybody can offer help as to what code I should include and where I should include it to display the sender's IP address I would greatly appreciate it.

$body = "Name: $name 

Email: $email 

Comments: $comments";

replace with

$body = "Name: $name 

Email: $email 

Comments: $comments 

IP: ".$_SERVER['REMOTE_ADDR'];

I know this is a pretty old question, but I though about helping who arrives on this one. First, I would recommand Contact form 7 plugin for creating a form with wordpress.

It could look like this at the creation of the form:

enter image description here

you add in the body of your message (in the screenshot in the right column "Message Body") the following short code :

[wpcf7.remote_ip]

Your message would (without modification) look like:

From: [your-name] <[your-email]> Subject: [your-subject]

Message Body: [your-message]

Sent from: [wpcf7.remote_ip]

--

This e-mail was sent from contact form on Testing (heep://localhost:8888/wordpress)

this will print the user IP into the email you'll receive.

Then in your post, you integrate the short code given into the page (like):

[contact-form-7 id="1056" title="Sample Form"]