Trouble getting Users IP - php

The form action is linked to this php script:
<?php
$email = $_POST['subscribefield'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Dit adres klopt niet";
die();
}
$to = "flash1996mph#hotmail.com";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";
mail($to, $subject, $body);
echo "U bent succesvol aangemeld voor de Vandenberg nieuwsbrief";
echo $_SERVER['REMOTE_ADDR'];
?>
At the end i added echo $_SERVER['REMOTE_ADDR']; then i checked my mail, but there was nothing. Did i use the code the wrong way?
EDIT:
<?php
$email = $_POST['subscribefield'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Dit adres klopt niet";
die();
}
$to = "flash1996mph#hotmail.com";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";
$body .= $_SERVER['REMOTE_ADDR'];
mail($to, $subject, $body);
echo "U bent succesvol aangemeld voor de Vandenberg nieuwsbrief";
?>
The above is an edit^

When mail is called the email is sent. In your script $body is the body of the email so append the IP address on to that variable before you call the mail function.
$to = "flash1996mph#hotmail.com";
$subject = "Abonee voor de nieuwsbrief";
$body = "$email \n Heeft zich aangemeld voor de nieuwsbrief";
$body .= $_SERVER['REMOTE_ADDR'];
mail($to, $subject, $body);
The echo currently just outputs the IP on the browser.

Related

PHP doesnt send paragraphs in email?

i am making a website where you can send tips to a email but the tip is shown as a whole block and not with paragraphs while the tip is shown with paragraphs at the website?
Here u can see it in the email:
Email
Here is the php code i use to send the email:
if(!is_a($entry, WP_Error) && rgar($entry, '2') == $_GET['email']) {
$toEmail = $_GET['email'];
$fromName = get_option('blogname');
$fromEmail = get_option('admin_email');
$to = $toEmail;
$subject = 'Hierbij uw eerste tip: '.$recent_posts[0]["post_title"];
$headers = "From: ".$fromName." <".$fromEmail.">\r\n";
$headers .= "Reply-To: ".$fromEmail."\r\n";
if(isset($ccMail) && $ccMail!=""){$headers .= "CC: ".$ccMail."\r\n";}
if(isset($BccMail) && $BccMail!=""){$headers .= "Bcc: ".$BccMail."\r\n";}
$headers .= 'X-Mailer: PHP v'.phpversion()."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8";
$message = '<html><body>';
$message .=
'<a href="http://inreach.nl" target="_blank" style="text-decoration:none">
<img src="http://inreach.nl/wp-content/themes/new_inreach/images/logo-inreach-grey.png" alt="Inreach-name" /></a><br><br>
Beste '.rgar($entry, 1).',<br><br>
Hebbes!
<br><br>
Jouw leiderschapsontwikkeling is gestart met deze eerste tip voor effectiever leiderschap. Veel succes met het inzetten van de kennis!<br><br>
<b>'.$recent_posts[0]["post_title"].'</b><br><br>
<div ><img style="max-width:100%" src="'.$image[0].'" alt="photo"/></div><br><br>
'.$recent_posts[0]["post_content"].' <br><br><br><br>
Wil jij over een specifieke situatie of case een tip? Mail me dan! Binnen twee dagen krijg je een persoonlijke reactie waar je mee verder kan.
<br><br>
Weet jij anderen die baat kunnen hebben bij deze tips? Stuur deze mail dan door naar ze! Zij kunnen zich aanmelden door HIER te klikken.
<br><br>
Hartelijke groet,
<br><br>
Steven Brouwers
<br><br>
p.s.: toch afmelden? Dat kan HIER ';
$message .= '</body></html>';
$sent = wp_mail($to,$subject,$message,$headers);
If think it's not a problem about paragraphs. Assuming $recent_posts[0]["post_content"] is a string with \n for new lines, you could try to use nl2br.
Replace:
$recent_posts[0]["post_content"]
With:
nl2br($recent_posts[0]["post_content"])
It should work. If not, try to inspect what's in $recent_posts[0]["post_content"].
try putting the following code before wp_mail();
function wpdocs_set_html_mail_content_type() {
return 'text/html';
}
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
use table instead of div in your $message.
it will work then

Norwegian letters "æ, ø, å" not showing when contact form is submitted

I have created a contact form, you can view it here. When I fill out the contact form and go to my inbox folder - the Norwegian letters æ, ø, å aren't shown in the message.
This is what I have currently added:
<meta http-equiv="content-type" content="text/html" charset="ISO-8859-1">
I have also tried <form accept-charset="ISO-8859-1">, but with no luck.
Here is a screenshot from the e-mail I receive after contact form has been submitted
as you can see there are no æ, ø, å letters.
Is there any way I can fix this?
PHP Code:
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$number = $_POST['number'];
$from = 'Ny melding sendt fra kontaktskjema på Helsespesialisten.no';
$to = 'test#test';
$subject = 'Helsespesialisten | Du har motatt en ny melding';
$body = "Fra: $name\n E-post: $email\n Telefonnummer: $number\n Melding: $message\n";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Vennligst skriv inn ditt navn';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Vennligst skriv inn din e-post';
}
//Check if message has been entered
if (!$_POST['number']) {
$errNumber = 'Vennligst skriv inn ditt telefonnummer';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Vennligst skriv en melding';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errNumber && !$errMessage) {
if (mail ($to, $subject, $body, $from, $number)) {
$result='<div class="alert alert-success">Takk for din henvendelse! Vi tar kontakt i løpet av kort tid!</div>';
} else {
$result='<div class="alert alert-danger">Beklager, en feil skjedde! Kontakt oss på: +47 35 11 15 40</div>';
}
}
}
Try this:
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$number = $_POST['number'];
$from = 'Ny melding sendt fra kontaktskjema på Helsespesialisten.no';
$to = 'test#test';
$subject = 'Helsespesialisten | Du har motatt en ny melding';
$headerFields = array(
"From: $from",
"MIME-Version: 1.0",
"Content-Type: text/html;charset=utf-8"
);
$body = "Fra: $name\n E-post: $email\n Telefonnummer: $number\n Melding: $message\n";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Vennligst skriv inn ditt navn';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Vennligst skriv inn din e-post';
}
//Check if message has been entered
if (!$_POST['number']) {
$errNumber = 'Vennligst skriv inn ditt telefonnummer';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Vennligst skriv en melding';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errNumber && !$errMessage) {
if (mail ($to, $subject, $body, implode("\r\n", $headerFields))) {
$result='<div class="alert alert-success">Takk for din henvendelse! Vi tar kontakt i løpet av kort tid!</div>';
} else {
$result='<div class="alert alert-danger">Beklager, en feil skjedde! Kontakt oss på: +47 35 11 15 40</div>';
}
}
}

Php form gives nothing

I'm quite new to php and am trying to make a simple form that mails the form-data to a specified mail address. I used this script here and modified it to my needs but when I try it out it just does nothing. It will go to the php page but nothing else happens and the page is empty.
Here is my HTML form:
<form class="contact" name="contact" method="post" action="./files/php/contact_send.php">
<table id="form">
<tr>
<td class="data-right"><label for="naam"><b>NAAM</b></label></td>
<td class="data-left">
<input type="text" name="naam" size="50" style="border-style:inset"/>
</td>
</tr>
<tr>
<td class="data-right"><label for="mailadres"><b>E-MAILADRES</b></label></td>
<td class="data-left">
<input type="text" name="mailadres" size="50" style="border-style:inset"/>
</td>
</tr>
<tr>
<td class="data-right"><label for="boodschap"><b>BOODSCHAP</b></label></td>
<td class="data-left">
<textarea name="boodschap" cols="39" rows="4" style="border-style:inset"></textarea>
</td>
</tr>
</table>
<input type="image" src="./files/img/stuur.png"
onmouseover="this.src='./files/img/stuur-hover.png'"
onmouseout="this.src='./files/img/stuur.png'"
alt="Stuur" width="150px" name="submit" value="Submit" />
</form>
and my php code:
<?php
if(isset($_POST['mailadres'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "blabla#gmail.com";
$email_subject = "Contact";
function died($error) {
// your error code can go here
echo "Het spijt ons maar er is iets fout gelopen bij het versturen van het formulier";
echo "Hieronder zijn de fouten weergegeven:<br /><br />";
echo $error."<br /><br />";
echo "Verbeter de fouten en probeer opnieuw.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['naam']) ||
!isset($_POST['mailadres']) ||
!isset($_POST['boodschap'])) {
died('Het spijt ons maar het lijkt er op dat er iets mis is gelopen met de gegevens die u heeft ingevuld.');
}
$naam = $_POST['naam']; // required
$mailadres = $_POST['mailadres']; // required
$boodschap = $_POST['boodschap']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$mailadres)) {
$error_message .= 'Het e-mailadres dat u heeft opgegeven is geen geldig e-mailadres.<br />';
}
$naam_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($naam_exp,$naam)) {
$error_message .= 'De naam die u heeft opgegeven is geen geldige naam.<br />';
}
if(strlen($boodschap) < 5) {
$error_message .= 'De opgegeven boodschap is niet lang genoeg, gelieve minstens 5 letters te gebruiken.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Formulier details:\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Naam: ".clean_string($naam)."\n";
$email_message .= "E-mail: ".clean_string($mailadres)."\n";
$email_message .= "Boodschap: ".clean_string($boodschap)."\n";
// create email headers
$headers = 'From: '.$mailadres."\r\n".'Reply-To: '.$mailadres."\r\n" .'X-Mailer: PHP/' phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
Bedankt om ons te contacteren. We proberen zo spoedig mogelijk met u contact op te nemen.
<?php
}
die();
?>
You have a syntax error at this line:
$headers = 'From: '.$mailadres."\r\n".'Reply-To: '.$mailadres."\r\n" .'X-Mailer: PHP/' phpversion();
You forgot a dot in your string concatination at phpversion(). Change it to:
$headers = 'From: '.$mailadres."\r\n".'Reply-To: '.$mailadres."\r\n" .'X-Mailer: PHP/'. phpversion();
The reason why you got an empty screen is because php is probably not displaying the error. This is a security measure. You can force php to report and display the errors by adding the next lines to the top of your script:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
You should remove these lines in a production environment because it is a security risk.
Replace:
if(!isset($_POST['naam']) ||
!isset($_POST['mailadres']) ||
!isset($_POST['boodschap'])) {
died('Het spijt ons maar het lijkt er op dat er iets mis is gelopen met de gegevens die u heeft ingevuld.');
}
with:
if ( (!isset($_POST['naam'])) ||
(!isset($_POST['mailadres'])) ||
(!isset($_POST['boodschap'])) ) {
died('Het spijt ons maar het lijkt er op dat er iets mis is gelopen met de gegevens die u heeft ingevuld.');
}
You were missing a lot of brackets for this statement.
Also, change the bottom part from:
?>
Bedankt om ons te contacteren. We proberen zo spoedig mogelijk met u contact op te nemen.
<?php
}
die();
?>
To:
echo "Bedankt om ons te contacteren. We proberen zo spoedig mogelijk met u contact op te nemen.";
}
die();
?>

How to get a popup box after submitting a form?

[SOLVED] Thanks everyone that replied.
I've got a PHP script that is run after a user submited a contact form.
This script shows a message in the top left corner saying if it worked properly or if it encountered a problem.
Now my question is, how can I put those messages into a popup box?
I know there is JS involved, but I barely have knowledge of that.
( Example: http://www.dylanvanheugten.nl/contact.php)
PHP
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Site Contact';
$to = 'info#dylanvanheugten.nl';
$subject = $_POST['subject'];
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '' && $subject != '' && $message != '') {
if ($human == '12') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Uw bericht is verzonden.<br/> U krijgt binnen 3 werkdagen een bericht terug.</p>';
} else {
echo '<p>Er is iets mis gegaan tijdens het versturen van uw bericht.<br/> Probeert u alstublieft nogmaals.</p>';
}
} else if ($_POST['submit'] && $human != '12') {
echo '<p>U heeft de spam preventie som foutief beantwoord.</p>';
}
} else {
echo '<p>Alstublieft alle velden invullen.</p>';
}
}
HTML
<form method="post" action="contact.php">
<label>Naam</label>
<input name="name" placeholder="Naam">
<label>Email</label>
<input name="email" type="email" placeholder="Email">
<label>Onderwerp</label>
<input name="subject" placeholder="Onderwerp">
<label>Bericht</label>
<textarea name="message" placeholder="Laat hier ook uw telefoonnummer achter als u telefonisch contact wilt."></textarea>
<label><strong>*Spam preventie*</strong><br/>Wat is 11+1?</label>
<input name="human" placeholder="11 + 1 =">
<input id="submit" name="submit" type="submit" value="Verzend">
<label><u>Alle velden zijn verplicht.</u></label>
</form>
Enclose your echo with <script> tags like this.
echo '<script>alert("Alstublieft alle velden invullen");<script>';
In the same way that you can print HTML from PHP, you can 'print' javascript. Here's an example with an alert box:
print("<script>window.alert('This is a javascript alert from PHP');</script>");
You are able to put your PHP variables inside of the statement, as well, if you need to.
You can simply alert msg like,
$msg='';
if ($_POST['submit']) {
if ($name != '' && $email != '' && $subject != '' && $message != '') {
if ($human == '12') {
if (mail ($to, $subject, $body, $from)) {
$msg='Uw bericht is verzonden.<br/> U krijgt binnen 3 werkdagen een bericht terug';
} else {
$msg='Er is iets mis gegaan tijdens het versturen van uw bericht.<br/> Probeert u alstublieft nogmaals.';
}
} else if ($_POST['submit'] && $human != '12') {
$msg='U heeft de spam preventie som foutief beantwoord.';
}
} else {
$msg='Alstublieft alle velden invullen.';
}
echo '<script>
alert("'.$msg.'");
</script>';
// you can replace the above javscript code to any plugin like jquery ui modal box
}
Add some javascript to the top of your html markup where you define a method to display a popup. Something like this:
<script type="text/javascript">
function displayPopup()
{
alert("Form submitted!");
}
</script>
Then within your PHP when the form has been submitted, just call the method displayPopup() method within a script tag.
You can certainly optimise the approach above, but it should give you somewhere to start.
Store the error message in a variable and simply echo them in the required div.
if ($_POST['submit'])
{
if ($name != '' && $email != '' && $subject != '' && $message != '')
{
if ($human == '12')
{
if (mail ($to, $subject, $body, $from))
{
$message = '<p>Uw bericht is verzonden.<br/> U krijgt binnen 3 werkdagen een bericht terug.</p>';
} else
{
$message = '<p>Er is iets mis gegaan tijdens het versturen van uw bericht.<br/> Probeert u alstublieft nogmaals.</p>';
}
} else if ($_POST['submit'] && $human != '12')
{
$message = '<p>U heeft de spam preventie som foutief beantwoord.</p>';
}
}
else
{
$message = '<p>Alstublieft alle velden invullen.</p>';
}
}
And in your HTML, you can create a and display the error inside it:
<div id="errorMessage"> <?php echo $message; ?> </div>
Try with this code
if ($query) {
echo "<script type='text/javascript'>alert('data Updated successfully!'); window.location.href = 'home.php';</script>";
} else {
echo "<script>alert('ERROR! Something Went wrong. Try Again')</script>";
}

Php contact form errors

I'm building a php contact form that checks if some fields are filled it or not (no ajax).
The form is not working for 100%. I will try to explain. When I submit my form, The user navigates to http://mydomain.com/send.php
There is receive my error messages (if there are any). When I refresh the send.php page I receive the following errors: Notice: Undefined index: name in /Library/WebServer/Documents/~aledvertising/send.php
Here is my code
html form
<form method="post" action="send.php">
<div id="form-top">
</div>
<div id="form-left">
<label>Naam:<span class="star">*</span></label>
<input name="name" placeholder="Uw naam">
<label>Email:<span class="star">*</span></label>
<input name="email" type="email" placeholder="Uw email">
<label>Hoeveel is 2+2? (Anti-spam)<span class="star">*</span></label>
<input name="human" placeholder="Uw antwoord">
</div>
<div id="form-right">
<label>Uw bericht:<span class="star">*</span></label>
<textarea name="message" placeholder="Uw bericht"></textarea>
</div>
<input id="submit" name="submit" type="submit" value="Verzenden">
</form>
SEND.PHP
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: ' . $_POST['email'];
$to = 'myemail#mail.com' . ', ';
$to .= $_POST['email'];
$subject = 'Uw vraag op www.aledvertising.be';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\nMessage:\n $message";
?>
<?php
if ($_POST['submit']) {
if ($name != '' && $email != '' && $message != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p class="green">Uw bericht is succesvol verzonden.</p>';
} else {
echo '<p>Er iets misgelopen, probeer opnieuw aub.</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>2+2 is niet gelijk aan het getal dat u hebt ingevoerd.</p>';
}
} else {
echo '<p>Alle velden met een * zijn verplicht in te vullen.</p>';
}
}
?>
Can somebody please help me to get a full working form? Thank you
You should see isset method from php.
<?php
if(isset($_POST["name"]))
{
//code here
}
?>
The problem is that when you reload the page, the server side code looks for the index name and it does not find it because name does not have any value yet. The value is received once you submit the page. So that's why the error is there.
update
The error is that when you submit the form, there are some fields that may be send empty, so once that the post values goes to send.php there are $_POST that will be expecting values. if some of them do not recive does values, it will tell you: "Hey, i do not have values, so i im null". That why you have to check that the fields are all filled or make a validation on server side.
<?php
if(isset($_POST["name"],$_POST["last_name"],etc,etc))
{
//if everything ok, ill go on.
}
else{
//if there are empty field, go back
}
?>
UPDATE 2
if (isset($_POST['name'],$_POST['email'],$_POST['message'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: ' . $_POST['email'];
$to = 'myemail#mail.com' . ', ';
$to .= $_POST['email'];
$subject = 'Uw vraag op www.aledvertising.be';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\nMessage:\n $message";
if ($name != '' && $email != '' && $message != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p class="green">Uw bericht is succesvol verzonden.</p>';
} else {
echo '<p>Er iets misgelopen, probeer opnieuw aub.</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>2+2 is niet gelijk aan het getal dat u hebt ingevoerd.</p>';
}
} else {
echo '<p>Alle velden met een * zijn verplicht in te vullen.</p>';
}
}
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: ' . $_POST['email'];
$to = 'myemail#mail.com' . ', ';
$to .= $_POST['email'];
$subject = 'Uw vraag op www.aledvertising.be';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\nMessage:\n $message";
if ($name != '' && $email != '' && $message != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p class="green">Uw bericht is succesvol verzonden.</p>';
} else {
echo '<p>Er iets misgelopen, probeer opnieuw aub.</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>2+2 is niet gelijk aan het getal dat u hebt ingevoerd.</p>';
}
} else {
echo '<p>Alle velden met een * zijn verplicht in te vullen.</p>';
}
}
?>
setting the isset() function and then declaring the variables worked for me, tested it in my server, not giving any errors and form is submitted successfully...
please check it once...

Categories