Contact Form IP Address - php

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 \n\nEmail: $email \n\nComments: $comments";
replace with
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments \n\nIP: ".$_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:
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"]

Related

opencart additional email recipent from contact form

I am trying to edit contact.php file of opencart so that it send email to multiple email id when a contact form is filled.
$mail->setTo($this->config->get('config_email'));
tried
$mail->setTo($this->config->get('config_email'),'manager#domain.com','ceo#domain.com');
Above edit did not work. How to hard code additional email ids? in such way that reply all works when replied by anyone of recipient from his email box.
If you check the source code of the SMTP adapter for Opencart, you can see that the to address accepts an array (as follows):
if (is_array($this->to)) {
$to = implode(',', $this->to);
} else {
$to = $this->to;
}
So, you could update your code as follows and pass the addresses in as an array:
$mail->setTo(array(
$this->config->get('config_email'),
'manager#domain.com',
'ceo#domain.com'
));

PHP-Read Receipt

I have a contact form where you specify the contact Information along with your email id. Once the form is sent it comes to my Inbox. The mail specifies the Information supplied by the user. I would like the sender of the contact form to receive a read receipt once I open the email.
This is what I have done so far
$name=$_POST['name'];
$email_address = $_POST['email'];
$subject='Contact Form Replies';
$phone=$_POST['phone'];
$message=$_POST['msg'];
$body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email_address\n Phone Number: $phone \n Message: $message \n ";
$headers = 'From: ' .$email_address. ''.
$headers .= 'X-Confirm-Reading-To: '.$email_address. '';
mail('xyz#gmail.com', $subject, $body,$headers))
?>
Now as per this code the mail gets successfully delivered to my Inbox. But once I open the mail, the read receipt does not go to the sender. Kindly advice on how I can overcome this Issue
Most email (web) clients disable any ability for the sender to check if an email is opened. They disable JavaScript, disable external sources so this is only possible with a own email server where users all use the same software such as outlook to have a reliable result.
However one possible way is to add an HTML image linking to image.php?receit=1234 and let that load up a php script that returns a tracking pixel. Now you know the email is opened and the user clicked the button to show all images.

How to show only the name instead of the email address of the sender in a simple php mail script

I have a simple php mail script which will send emails.
The problem is while sending it is displaying sendername <senderemail#domain.com>
I have given in the code as $headers = "From: $name <$senderEmail>";
I want to display only name and not email address of the sender.
How do I do that?
Here is the program in its entirety.
<?php
if($_POST["submit"]) {
$recipient=$_POST["senderemail"];
$subject=$_POST["subject"];
$name=$_POST["name"];
$senderEmail=$_POST["email"];
$city=$_POST["city"];
$headers = "From: $name <$senderEmail>";
$mailBody="$city\n";
$process=explode(",",$recipient);
reset($process);
foreach ($process as $to) {
mail($to,$subject, $mailBody,$headers);
}
$thankYou="<p>Thank you! Your Message has been sent.</p>";
echo 'Thank you! Your Message has been sent.';
}
?>
A From header containing both name and address should be formatted like this:
From: User Name <user#example.com>
If you don't provide a name, it will display the email address.
PHPMailer has built-in support for creating this header correctly for you via the From and FromName properties, and the setFrom method (it doesn't matter which you use):
$mail->setFrom('user#example/com', 'User Name');
or
$mail->From = 'user#example/com';
$mail->FromName = 'User Name';
Your generated message already seems to contain the user's full name in the From: header (assuming $name is the human-readable name). How this is displayed by any individual user agent is no longer in your hands. Very often, it will display both parts regardless; or only shorten to the human-readable name if the sender's email address is in the recipient's address book. (Thunderbird takes this a step further and displays the information from the address book rather than the actual information in the message!)
One common problem is if the generated message has a different Sender: header; often, this will cause the recipient's user agent to display more than just the usual full name. Your question doesn't mention this, nor does it show one of the generated messages; but perhaps this will help you find a solution.

AutoSend a custom HTML email to the user who has submitted the form

I have already my own PHP Form working.. If someone fills my FORM and they will submit it.
I will recieve a email with all the filled details. Like: Name, Firstname, Email, Tel etc.
But i want that if someone will submit the form, they will recieve automaticly a Custom Email.
Example: User will fill all the details in the form and press send.
Then he will receive a email from me like: Hai Ben, Thanks for submitting my form.. I will contact you a.s.a.p
Right now the form is only sending MY an email with al the details..
But i want that Ben will get a confirmation e-mail. So if Ben will fill in as email: info#ben.com then the confirmation email has to go there
Show us your code so that we can suggest you, how to modify it to get what are you trying to achieve. There will be many different ways to do things, and the best would depend on how rest of your codes are.
Just like you are calling mail function in your code to email yourself with the details, you can call the mail function to send him an email.
Also, you dont hardcode info#ben into the script. You can just collect his email from the POST variables.
Sample, assuming your form works on POST and the email is stored in email in the post variables.
$send = mail($_POST['email'], $subject, $messagebody, $header);
Now do the bit of tinkering you would need to get it working with your script.
Here is the example code for sending email:
$from = $_POST['email'];
$to = 'your-email#email.com';
$subject = "Title here";
$messagebody = <<<EMAIL
Thanks for submitting my form..
I will contact you a.s.a.p
EMAIL;
$header = "From: $from";
$send = mail($to, $subject, $messagebody, $header);

How do i create an email contact form for my website

I'm looking to create a form on my website where users can enter their email address and a message (however long). Then upon clicking on a submit button, the code, sends the message as an email to my mailbox.
I was wondering if someone knew what code i could use. I am using PHP as my server-side language.
You need to have access to an smtp server somewhere. Assuming you do, use the php mail function to send the mail like so:
$Name = "John doe"; //senders name
$email = "email#adress.com"; //senders e-mail adress
$recipient = "recipient#emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for receiver"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
mail($recipient, $subject, $mail_body, $header);
The smtp server is set in the php.ini file in these two lines:
SMTP = servername
smtp_port = 25
More information at w3schools site.
while the above two answers provide a basic email sending suggestion, there's one thing you should consider, the codes are not secure. spammers can inject Cc: codes and send spam using the form. if they do, your smtp provider may ban your account. try a dedicated mailer, like phpmailer
Try to use PHPForms. It is an ultimate web form builder that allows to create professionally looking email forms within just a few minutes. You will only need to create a PHP form by means of an intuitive interface and generate a code that can be easily copied and pasted to any web page.

Categories