I'm in need of assistance with this if/else statement - php

I'm doing a contact page for my site, the text is in Portuguese because I'm Brazilian, but my problem is the following: when I send parameters with ?resp=true it always enters in the first condition and I'm not able to figure out what is going wrong.
Why is the first condition met when the parameter is ?resp=true ? , here is the code that I currently have problems on:
<?php if (isset($_GET["resp"]) && $_GET["resp"] == false) { ?>
<div class="row row-centered" style="padding-top: 10px;">
<div class="alert alert-success">
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<strong style="text-align: center;">Sua mensagem foi enviada com sucesso.</strong>
</div>
</div>
<?php } elseif(isset($_GET["resp"]) && $_GET["resp"] == true) { ?>
<div class="row row-centered" style="padding-top: 10px;">
<div class='alert alert-danger'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<strong style="text-align: center;">Desculpe, parece que o servidor de email não esta respondendo. Por favor, tente novamente mais tarde!</strong>
</div>
</div>
<?php } ?>

All values recieved via the POST or GET methods (ie. in the REQUEST) are automatically seen as strings. So trying to check:
<?php
if($_GET['resp'] == true) {}
?>
will return false, and thus not enter the loop. What you want is to check the string value (instead of the boolean)
<?php
if($_GET['resp'] == 'true') {)
?>

You are actually trying to compare a string value to a boolean value. Since all that comes from form submit is in form of string only. So i have replaced boolean true and false with 'true' and 'false'
Try this code:
<?php if (isset($_GET["resp"]) && $_GET["resp"] == 'false') { ?>
<div class="row row-centered" style="padding-top: 10px;">
<div class="alert alert-success">
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<strong style="text-align: center;">Sua mensagem foi enviada com sucesso.</strong>
</div>
</div>
<?php } elseif(isset($_GET["resp"]) && $_GET["resp"] == 'true') { ?>
<div class="row row-centered" style="padding-top: 10px;">
<div class='alert alert-danger'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<strong style="text-align: center;">Desculpe, parece que o servidor de email não esta respondendo. Por favor, tente novamente mais tarde!</strong>
</div>
</div>
<?php } ?>

Related

Include function to mail php smtp

I want send email to user with all elements it payed.
I tried the next:
First create a function called listItemsBought
function listItemsBought() {
$counter=0;
foreach ($_SESSION["shopping_cart"] as $product) { ++$counter; ?>
<div class="card overflow-hidden">
<div class="ribbon ribbon-top-right text-danger"><span class="bg-danger"><?php echo $product["PreuProducte2"]; ?> €</span></div>
<div class="card-body item-user">
<div class="profile-pic mb-0">
<div class="d-md-flex">
<img src="imatges/projectes/<?php echo $product["NomProducte2"]; ?>/Logo/<?php echo $product["IMGProducte2"]; ?>" class="w-150 h-150 br-2" alt="user">
<div class="ml-4">
<h4 class="mt-1 mb-1 font-weight-bold"><?php echo $product["NomProducte2"]; ?><small class="text-muted text-small fs-13 ml-2">para <?php echo $product["CategoriaProducte2"]; ?></small></h4>
<span class="text-gray"><?php echo $product["Descrip2"]; ?></span><br>
<span class="text-muted">version: 1.6</span><br>
<div class="rating-stars d-inline-flex mb-2 mr-3">
<input type="number" readonly="readonly" class="rating-value star" name="rating-stars-value" value="4">
<div class="rating-stars-container mr-2">
<div class="rating-star sm is--active">
<i class="fa fa-star"></i>
</div>
<div class="rating-star sm is--active">
<i class="fa fa-star"></i>
</div>
<div class="rating-star sm is--active">
<i class="fa fa-star"></i>
</div>
<div class="rating-star sm is--active">
<i class="fa fa-star"></i>
</div>
<div class="rating-star sm">
<i class="fa fa-star"></i>
</div>
</div> 4.0
</div>
<h6 class="mb-0">$ 250.00 Buy <i class="ti-medall fs-16 mr-2"></i>Add To wishlist</h6>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
Then, I send Email to client via SMTP:
$output="
<table style=\"padding:15px 15px;background:#f4f4f4;width:100%;font-family:arial\" cellpadding=\"0\" cellspacing=\"0\">
<link rel=\"stylesheet\" href=\"https://use.fontawesome.com/releases/v5.8.1/css/all.css\" integrity=\"sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf\" crossorigin=\"anonymous\">
<tbody>
<tr>
<td>
<table style=\"max-width:540px;min-width:320px\" align=\"center\" cellspacing=\"0\">
<tbody>
<tr>
<td style=\"background:#fff;border:1px solid #d8d8d8;padding:30px 30px\" align=\"center\">
<table align=\"center\">
<tbody>
<tr>
<td style=\"border-bottom:1px solid #d8d8d8;color:#666;text-align:center;padding-bottom:30px\">
<table style=\"margin:auto\" align=\"center\">
<tbody>
<tr>
<td style=\"color:#005f84;font-size:22px;font-weight:bold;text-align:center;font-family:arial\">
ITEMS BOUGHTED
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style=\"color:#666;padding:15px;padding-bottom:0;font-size:14px;line-height:20px;font-family:arial;text-align:left\">
<div style=\"font-style:normal;padding-bottom:15px;font-family:arial;line-height:20px;text-align:left\">
<p> Hola <span style=\"font-weight:bold;color:#4296ce;font-size:16px\">$NomYCognom</span> <br>
<br>
You have completed payment on our website www.example.com </p>
<br>
<hr>
<br>
<b>You bought:<br></b>
$ItemsBoughted
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style=\"background:#f9f9f9;border:1px solid #d8d8d8;border-top:none;padding:15px 10px\" align=\"center\">
<table style=\"width:100%;max-width:650px\" align=\"center\">
<tbody>
<tr>
<td style=\"font-size:14px;line-height:20px;text-align:center;max-width:650px\">
<a style=\"text-decoration:none;color:#69696c\" target=\"_blank\">
<span style=\"color:#00ce00;font-weight:bold;max-width:180px\">BEST REGARDS:</span>
Payment System from <b>Example.com</b>
</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table style=\"max-width:650px\" align=\"center\">
<tbody>
<tr>
<td style=\"color:#b4b4b4;font-size:11px;padding-top:10px;line-height:15px;font-family:arial\">
<span> </span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
";
// Indicamos que el Contenido del mensaje está en la variable $output
$body = $output;
// Indicamos que el Asunto del mensaje es "ESRP - Reinici de contrasenya"
$subject = "Example - Payed Completed";
// Indicamos que debe enviar este correo a la dirección del usuario
$email_to1 = "$Email";
// El Email del remitente que envia el mensaje es "noreply#esrp.net"
$fromserver = "noreply#example.com";
// Requiere este archivo para enviar este mensaje
require("assets/enviarCorreos/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
// --------------------------------------------------------------------------------------------------- //
// Introducimos las credenciales de nuestro servidor SMTP
// --------------------------------------------------------------------------------------------------- //
$mail->SMTPSecure = 'tls'; // Tipo de Conexión
$mail->Host = " "; // Host del servidor SMTP
$mail->SMTPAuth = true; // ¿El servidor SMTP requiere identificación? (true/false)
$mail->Username = " "; // Nombre usuario del servidor SMTP (normalmente es un Email)
$mail->Password = " "; // Contraseña usuario del servidor SMTP
$mail->Port = 587; // Puerto del servidor SMTP
$mail->IsHTML(true); // El formato del mensaje a enviar, ¿es HTML?
$mail->From = "no-reply#example.com"; // El Email del remitente que envia el mensaje es "noreply#esrp.net"
$mail->FromName = "Example"; // El Nombre del remitente que envia el mensaje es "esrp"
$mail->Sender = $fromserver;
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($email_to1);
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
// Si no ocurre ningún error, se pone un Alert al usuario con el siguiente mensaje:
else{
// echo "Enviado";
}
I want show in variable $ItemsBoughted the results from function listItemsBought() where have list of items bought by client.
How I can do that?
In your first function create text string with all the html you need and return it.
function listItemsBought() {
$counter=0;
$html = ''; //edit made
foreach ($_SESSION["shopping_cart"] as $product)
{
++$counter;
$PreuProducte2 = $product['PreuProducte2'];
$NomProducte2 = $product['NomProducte2'];
$IMGProducte2 = $product['IMGProducte2'];
$product['NomProducte2'];
$CategoriaProducte2 = $product['CategoriaProducte2'];
$Descrip2 = $product['Descrip2'];
$html .= <<<EOD
<div class='card overflow-hidden'>
<div class='ribbon ribbon-top-right text-danger'><span class='bg-danger'>$PreuProducte2 €</span></div>
<div class='card-body item-user'>
<div class='profile-pic mb-0'>
<div class='d-md-flex'>
<img src='imatges/projectes/$NomProducte2/Logo/$IMGProducte2' class='w-150 h-150 br-2' alt='user'>
<div class='ml-4'>
<a href='userprofile.html' class='text-dark'><h4 class='mt-1 mb-1 font-weight-bold'>$NomProducte2<small class='text-muted text-small fs-13 ml-2'>para $CategoriaProducte2</small></h4></a>
<span class='text-gray'>$Descrip2</span><br>
<span class='text-muted'>version: 1.6</span><br>
<div class='rating-stars d-inline-flex mb-2 mr-3'>
<input type='number' readonly='readonly' class='rating-value star' name='rating-stars-value' value='4'>
<div class='rating-stars-container mr-2'>
<div class='rating-star sm is--active'>
<i class='fa fa-star'></i>
</div>
<div class='rating-star sm is--active'>
<i class='fa fa-star'></i>
</div>
<div class='rating-star sm is--active'>
<i class='fa fa-star'></i>
</div>
<div class='rating-star sm is--active'>
<i class='fa fa-star'></i>
</div>
<div class='rating-star sm'>
<i class='fa fa-star'></i>
</div>
</div> 4.0
</div>
<h6 class='mb-0'><a href='payments.html' class='btn btn-green font-weight-bold fs-14 mr-3'>$ 250.00 Buy</a> <a href='cart.html' class='btn btn-default font-weight-semibold text-green fs-14'><i class='ti-medall fs-16 mr-2'></i>Add To wishlist</a></h6>
</div>
</div>
</div>
</div>
</div>
EOD;
}
return $html;
}
Then in your second file just concatenate the function becasue it will return a string:
$output = " <sample html>" . listItemsBought() . "</sample html>

Block registration if email already exists in mysqli database

Users can use the same email address for different registration.
Tried using different solutions from developers on Stack Overflow who have experienced the same problems that I have, including making the emailUsers column a UNIQUE KEY in the database table, and implementing some sort of jQuery, but not successful. Think the problem is I am missing an 'else if' block for duplicate email, but all the various ways I tried to implement this, it does not do anything.
<div id="signup">
<div class="container">
<div class="row">
<div class="col-sm-6 offset-sm-1">
<div class="signup-left position-fixed text-center">
<img src="img/200.png">
<br><br><br>
<?php
if(isset($_GET['error']))
{
if($_GET['error'] == 'emptyfields')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Fill In All The Fields
</div>';
}
else if ($_GET['error'] == 'invalidmailuid')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid email and user name
</div>';
}
else if ($_GET['error'] == 'invalidmail')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid email
</div>';
}
else if ($_GET['error'] == 'invaliduid')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid user name
</div>';
}
else if ($_GET['error'] == 'passwordcheck')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Passwords donot match
</div>';
}
else if ($_GET['error'] == 'usertaken')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> This User name is already taken
</div>';
}
else if ($_GET['error'] == 'invalidimagetype')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Invalid image type
</div>';
}
else if ($_GET['error'] == 'imguploaderror')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Image upload error, please try again
</div>';
}
else if ($_GET['error'] == 'imgsizeexceeded')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Image too large
</div>';
}
else if ($_GET['error'] == 'sqlerror')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Website Error: </strong> Contact admin to have the issue fixed
</div>';
}
}
else if (isset($_GET['signup']) == 'success')
{
echo '<div class="alert alert-success" role="alert">
<strong>Signup Successful</strong> Please Login from the login menu
</div>';
}
?>
<form id="signup-form" action="includes/signup.inc.php" method='post' enctype="multipart/form-data">
<input type="submit" class="btn btn-light btn-lg" name="signup-submit" value="Signup">
<br><br>
<a href="login.php">
<i class="fa fa-sign-in fa-2x social-icon" aria-hidden="true"></i>
</a>
<a href="contact.php">
<i class="fa fa-envelope fa-2x social-icon" aria-hidden="true"></i>
</a>
</div>
</div>
I want to be able to block a user from registering with the same email, and to generate an error message when the user tries to do this.
EXTRA INFO: Can post further, detailed methods of me trying to make the emailUsers column a UNIQUE KEY, but when I do this, new users can no longer register, even if they use a different email.

php errors when logged out because of session user_id

I'm making a product details page, and on the product details page I'm having if functions to see if the $_SESSION user_id is the same as the $product user_id to echo something or not for example. When no user is logged in, I get alot of errors that it can't find the $session user_id. How can I solve this problem so when there is no user logged in it does the same as if the session user_id is wrong to the product user_id?
for example:
<?php if ( $_SESSION['user_id'] != $product["user_id"]): ?>
<h3>Email van de eigenaar:</h4>
<?php echo $userarray['email'];?>
<?php endif; ?>
</div>
So if the session user_id is wrong to the product user_id i want the same thing to happen when there is no $_SESSION user_id found which is echoing this: <?php echo $userarray['email'];?>
This is my whole details page:
<?php include_once ('templates/header.php'); ?>
<div class="all-content">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<!-- Maak variables voor gele balkje ingelogt of niet -->
<?php $overditcadeau = '<center>Over dit cadeau</center>'; ?>
<?php $mijncadeau = '<center>Mijn cadeau</center>'; ?>
<?php if ($_SESSION['user_id'] != $product["user_id"]) {
echo $overditcadeau;
} else {
echo $mijncadeau;
} ?>
</div>
</div>
<div class="container">
<br><br>
<?php $userarray = $this->db->get_Where('users', array('user_id'=>$product["user_id"]))->row_array(); ?>
<!-- Als het cadeau niet van de ingelogde gebruiker is laat email van de eigenaar van het cadeau zien -->
<?php if ( $_SESSION['user_id'] != $product["user_id"]): ?>
<h3>Email van de eigenaar:</h4>
<?php echo $userarray['email'];?>
<?php endif; ?>
</div>
<div class="container">
<div class="row">
<div class="overditcadeau" >
<div class="overditcadeau_foto">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto']; ?>" id="cadeaufoto_overditcadeau">
</div>
<div class="overditcadeau_tekst1">
<h1> <div class="product_naam"> <?php echo $product['product_naam']; ?> </div> </h1>
<h3>Over dit cadeau</h3>
<div class="product_beschrijving"><?php echo $product['product_beschrijving']; ?> </div>
</div>
<div class="overditcadeau_tekst2">
<!--Als het cadeau niet van de ingelogde gebruiker is laat een button zien dat heet cadeau aanvragen -->
<div class="cadeau_aanvragen">
<?php if ( $_SESSION['user_id'] != $product["user_id"]): ?>
<button type="button" class="btn btn-default">Ik wil dit cadeau!</button>
<button onclick="myFunction()">Ik wil dit cadeau!</button>
<script>
function myFunction() {
alert("Uw cadeau aanvraag is geaccepteerd, Klik hier om een bericht naar de eigenaar van het cadeau te sturen.");
}
</script>
<?php endif; ?>
</div>
<!--Als het cadeau van de ingelogde gebruiker is laat een button zien dat heet cadeau bewerken-->
<div class="cadeau_bewerken">
<?php if ( $_SESSION['user_id'] == $product["user_id"]): ?>
<a class="btn btn-primary" href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product['product_id']; ?>"> Cadeau bewerken </a>
<?php endif; ?>
</div>
<br>
<div class="cadeau_verwijderen">
<?php if ( $_SESSION['user_id'] == $product["user_id"]): ?>
<a class="btn btn-primary" href="<?php echo base_url() ?>/Delete_ctrl/delete_product_id/<?php echo $product['product_id']; ?>"> Cadeau verwijderen </a>
<?php endif; ?>
</div>
<!--Als het cadeau van de ingelogde gebruiker is laat aantal geïnteresseerden zien-->
<div class="aantal_geinteresseerden">
<?php if ( $_SESSION['user_id'] == $product["user_id"]): ?>
<h4>Aantal geïnteresseerden:</h4>
<?php endif; ?>
</div>
<?php if ( $_SESSION['user_id'] != $product["user_id"]): ?>
<div class="aangeboden_door"> Aangeboden door:
<tr>
<td>
<a href="<?php echo base_url() . 'User/userdetails/'.$product['user_id']?>">
<?php echo $userarray['voornaam'];?>
</a>
</td>
</tr>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="container">
<footer>
<p>© kadokado 2017, Inc.</p>
</footer>
<hr>
</div>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
Use isset() to check variable is set or not.
Like below:-
if (isset($_SESSION['user_id']) && isset($product["user_id"]) && $_SESSION['user_id'] != $product["user_id"]) {
Note:- Do same for other variables too used on the page.
So the whole code need to be like below:-
<?php include_once ('templates/header.php'); ?>
<div class="all-content">
<div class="row">
<div class="col-lg-12 bg-warning" style="font-size:25px">
<!-- Maak variables voor gele balkje ingelogt of niet -->
<?php $overditcadeau = '<center>Over dit cadeau</center>'; ?>
<?php $mijncadeau = '<center>Mijn cadeau</center>'; ?>
<?php if (isset($_SESSION['user_id']) && isset($product["user_id"]) && $_SESSION['user_id'] != $product["user_id"]) {
echo $overditcadeau;
} else {
echo $mijncadeau;
} ?>
</div>
</div>
<div class="container">
<br><br>
<?php $userarray = $this->db->get_Where('users', array('user_id'=>$product["user_id"]))->row_array(); ?>
<!-- Als het cadeau niet van de ingelogde gebruiker is laat email van de eigenaar van het cadeau zien -->
<?php if (isset($_SESSION['user_id']) && isset($product["user_id"]) && $_SESSION['user_id'] != $product["user_id"]): ?>
<h3>Email van de eigenaar:</h4>
<?php echo $userarray['email'];?>
<?php endif; ?>
</div>
<div class="container">
<div class="row">
<div class="overditcadeau" >
<div class="overditcadeau_foto">
<img src="<?php echo base_url(); ?>upload/<?php echo $product['product_foto']; ?>" id="cadeaufoto_overditcadeau">
</div>
<div class="overditcadeau_tekst1">
<h1> <div class="product_naam"> <?php echo $product['product_naam']; ?> </div> </h1>
<h3>Over dit cadeau</h3>
<div class="product_beschrijving"><?php echo $product['product_beschrijving']; ?> </div>
</div>
<div class="overditcadeau_tekst2">
<!--Als het cadeau niet van de ingelogde gebruiker is laat een button zien dat heet cadeau aanvragen -->
<div class="cadeau_aanvragen">
<?php if (isset($_SESSION['user_id']) && isset($product["user_id"]) && $_SESSION['user_id'] != $product["user_id"]): ?>
<button type="button" class="btn btn-default">Ik wil dit cadeau!</button>
<button onclick="myFunction()">Ik wil dit cadeau!</button>
<script>
function myFunction() {
alert("Uw cadeau aanvraag is geaccepteerd, Klik hier om een bericht naar de eigenaar van het cadeau te sturen.");
}
</script>
<?php endif; ?>
</div>
<!--Als het cadeau van de ingelogde gebruiker is laat een button zien dat heet cadeau bewerken-->
<div class="cadeau_bewerken">
<?php if (isset($_SESSION['user_id']) && isset($product["user_id"]) && $_SESSION['user_id'] == $product["user_id"]): ?>
<a class="btn btn-primary" href="<?php echo base_url() ?>/KdGwController/details_bewerken/<?php echo $product['product_id']; ?>"> Cadeau bewerken </a>
<?php endif; ?>
</div>
<br>
<div class="cadeau_verwijderen">
<?php if (isset($_SESSION['user_id']) && isset($product["user_id"]) && $_SESSION['user_id'] == $product["user_id"]): ?>
<a class="btn btn-primary" href="<?php echo base_url() ?>/Delete_ctrl/delete_product_id/<?php echo $product['product_id']; ?>"> Cadeau verwijderen </a>
<?php endif; ?>
</div>
<!--Als het cadeau van de ingelogde gebruiker is laat aantal geïnteresseerden zien-->
<div class="aantal_geinteresseerden">
<?php if (isset($_SESSION['user_id']) && isset($product["user_id"]) && $_SESSION['user_id'] == $product["user_id"]): ?>
<h4>Aantal geïnteresseerden:</h4>
<?php endif; ?>
</div>
<?php if ( $_SESSION['user_id'] != $product["user_id"]): ?>
<div class="aangeboden_door"> Aangeboden door:
<tr>
<td>
<a href="<?php echo base_url() . 'User/userdetails/'.$product['user_id']?>">
<?php echo $userarray['voornaam'];?>
</a>
</td>
</tr>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="container">
<footer>
<p>© kadokado 2017, Inc.</p>
</footer>
<hr>
</div>
</div>
<div class="clearfix"></div>
<?php include_once ('templates/footer.php'); ?>
Only way is to check if $_SESSION['user_id'] is set everywhere you are using this.
As a quick fix (if you have a lot of references to $_SESSION['user_id']), you can put to your second line:
if (empty($_SESSION['user_id'])) $_SESSION['user_id'] = -1;

PHP Class not found while it's succesfully included

I have searched on this forum for a solution and other places as well. But I can't find the problem with the code I wrote. The php file called Email_Service.php looks like this:
<?php
////////////////////////////////////////
// [Email-Service] v3.5 /
//////////////////////////////////////
//Email Service Class
class EmailService {
//Properties
private $email_basis;
private $type;
//Constructor
function __construct($type) {
echo '[EmailService] type: ' . $type;
}
//Send Email function with passed on arrays from test_pagina.php
function versturen($emailInfo, $klantInfo) {
//Email info
$email_van = $emailInfo['email_van'];
$email_naar = $emailInfo['email_naar'];
$email_onderwerp = $emailInfo['email_onderwerp'];
//Controleer of het opgegeven email adres geldig is en geen rare tekens bevat
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
if (preg_match($pattern, trim(strip_tags($emailInfo['email_van'])))) {
$cleanedFrom = trim(strip_tags($emailInfo['email_van']));
} else {
return "The email address you entered was invalid. Please try again!";
}
//Hier word de email_template geopend voor elke type.
//Zorg vraag formulier
if ($emailInfo['type'] == 'zorgvraag') {
//$email_basis = file_get_contents(base_url() . 'include/email_template_zorgvraag.txt'); //(LOKAAL)
//file_get_contents(base_url() . "assets/email_template.txt"); //(ONLINE)
} else if ($emailInfo['type'] == 'aanmelden') {
//$email_basis = file_get_contents(base_url() . 'mail_php/email_template_aanmeldformulier.txt'); //(LOKAAL)
}
//Personaliseer de email door de velden te vervangen met de ingevulde parameters
$email_basis = str_replace("f_voornaam", $klantInfo['voornaam'], $email_basis);
$email_basis = str_replace("f_achternaam", $klantInfo['achternaam'], $email_basis);
$email_basis = str_replace("f_telefoon", $klantInfo['telefoon'], $email_basis);
$email_basis = str_replace("f_email", $klantInfo['email_van'], $email_basis);
$email_basis = str_replace("f_bericht", $klantInfo['$bericht'], $email_basis);
$email_basis = str_replace("f_locatie", $klantInfo['$locatie'], $email_basis);
//Genereer headers
$headers = "From: " . $cleanedFrom . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['f_email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//Hier word de mail verstuurd als alles goed is
if (mail($emailInfo['email_naar'], $emailInfo['email_onderwerp'], $email_basis, $headers)) {
//CC
mail('info#yourdomain.nl', $emailInfo['email_onderwerp'], $email_basis, $headers);
} else {
echo 'Er is iets fout gegaan. Probeer het later nog een keer!';
die();
}
}
}
?>
It's called from another php file called test_pagina.php which looks like this:
<?php
include 'https://yourdomain.nl/assets/Email_Service.php'; //ONLINE
//require base_url() . 'assets/Email_Service.php'; //LOKAAL
//Haal gemeeente uit de adres balk
$url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$url_onderdeel = explode('/', $url);
$gemeente = $url_onderdeel[4];
$gemeenteHoofdletter = ucfirst($gemeente);
//Email parameters
$email_van; $email_naar; $email_onderwerp = "Vraag van ". $gemeenteHoofdletter;
$voornaam; $achternaam;
$telefoon; $bericht;
$emailInfo; $klantInfo;
//Controleert de ingevulde velden
if (isset($_POST['f_email_van']) ||
isset($_POST['f_voornaam']) ||
isset($_POST['f_achternaam']) ||
isset($_POST['f_telefoon']) ||
isset($_POST['f_bericht'])) {
//Email info
$email_van = $_POST['f_email_van'];
$email_naar = "socialekaartpro#gmail.com";
/*Stuur Email
Dé Parameters:(emailInfo, klantInfo)*/
$emailInfo = array (
'email_van' => $email_van,
'email_naar' => $email_naar,
'email_onderwerp' => $email_onderwerp);
$klantInfo = array (
'voornaam' => $_POST['f_voornaam'],
'achternaam' => $_POST['f_achternaam'],
'telefoon' => $_POST['f_telefoon'],
'bericht' => $_POST['f_bericht'],
'locatie' => $gemeenteHoofdletter);
//Voeg de mail script toe zodat we de functie stuurEmail kunnen aanroepen
$mail = new EmailService('zorgvraag');
$mail -> versturen($emailInfo, $klantInfo);
}
?>
<!--=== Type Woning ===-->
<div class="page-topbar">
<div class="container">
<div class="row">
<div class="col-sm-4">
<h3>Bedrijfsnaam</h3>
</div>
<div class="col-sm-8 hidden-xs">
<ol class="breadcrumb">
<li>Gemeente Nijmegen</li>
<li>Woningverhuur</li>
<li class="active">Bedrijfsnaam</li>
</ol>
</div>
</div>
</div>
</div>
<div class="content container" style="padding-top: 10px;">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading left" style="margin-bottom: -1px;background-color: rgba(255, 255, 255, 0);"><i class="glyphicon glyphicon-menu-left"></i> Terug naar overzicht
<ul class="pull-right">
<i class="fa fa-print" aria-hidden="true"></i>Print
</ul>
</div>
</div>
</div>
</div>
</div>
<!--================================== Overzicht ========================-->
<div class="job-description">
<div class="container content">
<div class="row">
<div class="col-md-8">
<div class="left-inner" style="margin-left: 0px;">
<h3 style="margin-top: 28px;margin-bottom: 12px;">Test pagina</h3>
<p>
LEEG LEEG
</p>
<h3 style="margin-top: 40px;margin-bottom: 12px;">LEEG LEEG</h3>
<p>
LEEG LEEG
</p>
<h3 style="margin-top: 40px;margin-bottom: 12px;">LEEG LEEG</h3>
<p>
LEEG LEEG
</p>
<h3 style="margin-top: 40px;margin-bottom: 12px;">LEEG LEEG</h3>
<p>
LEEG LEEG
</p>
<br>
<br>
Naar de website LEEG LEEG
<br>
</div>
</div>
<div class="col-sm-4">
<div class="panel panel-default" style="margin-top: 9px;">
<div class="panel-heading" style="border-bottom-color: rgba(217, 217, 217, 0);margin-top: 2px;">Doelgroep</div>
<div class="panel-body">
<div class="row">
<p style="margin-top: -22px;margin-left: 16px;padding-right: 7px;">
LEEG | LEEG
</p>
</div>
</div>
<div class="panel-heading" style="border-bottom-color: rgba(217, 217, 217, 0);margin-top: -14px;">Leeftijdscatogarie</div>
<div class="panel-body">
<div class="row">
<p style="margin-top: -22px;margin-left: 16px;margin-bottom: 2px;">
LEEG | LEEG
</p>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-top: 9px;">
<div class="panel-heading" style="border-bottom-color: rgba(217, 217, 217, 0);margin-bottom: -15px;">Contact gegevens</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-4 col-md-4">
<p style="font-weight: 600;color: #000000;margin-bottom: 0px;">Naam</p>
<p style="font-weight: 600;color: #000000;margin-bottom: 0px;">Adres</p>
<p style="font-weight: 600;color: #000000;margin-bottom: 0px;">Postcode</p>
<p style="font-weight: 600;color: #000000;margin-bottom: 0px;">Plaats</p>
<p style="font-weight: 600;color: #000000;margin-bottom: 0px;">Telefoon</p>
</div>
<div class="col-xs-6 col-md-6" style="width: 65%;">
<p style="margin-bottom: 0px;">LEEG</p>
<p style="margin-bottom: 0px;">LEEG</p>
<p style="margin-bottom: 0px;">LEEG</p>
<p style="margin-bottom: 0px;">LEEG</p>
<p style="margin-bottom: 0px;">LEEG</p>
</div>
</div>
<hr style="margin-top: 20px;margin-bottom: 10px;">
<div class="row">
<div class="col-md-12">
<div class="panel-heading" style="margin-left: -15px;margin-top: -12px;margin-bottom: -15px;">
<h4 class="panel-title">
<span style="font-size: 13px;font-weight: 600;">Heeft u een zorgvraag, </span>
<a href="#mail-1" data-parent="#accordion-v1" data-toggle="collapse" class="accordion-toggle">
<span style="color: #3299bb;font-weight: 600;text-decoration: underline;"> klik dan hier</span>
</a>
</h4>
</div>
<!--Bevestiging script JSalert
<div>
<script src="https://socialekaartgemeente.nl/assets/js/sweetalert-dev.js"></script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<link rel="stylesheet" href="https://socialekaartgemeente.nl/assets/css/sweetalert.css">
<script type="text/javascript">
function JSalert(){
//event.preventDefault();;
swal("Congrats!", ", Uw mail is verzonden!", "success");
}
</script>
</div>-->
<!-- =============================[EMAIL FORM]================================== -->
<!-- onSubmit="window.location.reload()" -->
<!-- ="javascript:JSalert();" -->
<div class="panel-collapse collapse" id="mail-1">
<div class="panel-body" style="margin-left: -15px;">
<form action="" method="post" id="form_mail" >
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<input id="voornaam" type="text" name="f_voornaam" class="form-control" placeholder="Voornaam*" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input id="achternaam" type="text" name="f_achternaam" class="form-control" placeholder="Achternaam*" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input id="telefoon" type="text" name="f_telefoon" class="form-control" placeholder="Telefoonnummer*" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input id="email" type="text" name="f_email_van" class="form-control" placeholder="Email*" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<label class="sr-only" for="message">Bericht</label>
<textarea class="input-lg form-control" name="f_bericht" rows="5" id="bericht" placeholder="Uw zorgvraag"></textarea>
<span class="help-block"></span>
</div>
<!--Verzend knop-->
<button type="submit" class="btn btn-sm btn-primary" style="margin-bottom: -15px;">Bericht verzenden</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default" style="margin-top: 9px;">
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<ul class="social-icons pull-left" style="margin-left: -2px;margin-top: 4px;margin-bottom: -8px;">
<li style="margin-left: 0px;"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</div>
</div>
<!-- Google Maps -->
<div class="panel panel-default" style="margin-top: 9px;">
<div class="panel-body">
<!-- Laad Google Maps -->
<style>#map-container { height: 200px }</style>
<div id="map-container" class="col-md-12"></div>
<script src="//maps.google.com/maps/api/js?sensor=false"></script>
<script>
function init_map() {
//Definieer de coordinaten en zet zoom level
var var_location = new google.maps.LatLng(00000000, 00000000);
var var_mapoptions = {
center: var_location,
zoom: 14
};
//Plaats de marker bij de coordinaten
var var_marker = new google.maps.Marker({
position: var_location,
map: var_map,
title:"Venice"});
//^Teken the map met de instellingen hierboven^
var var_map = new google.maps.Map(document.getElementById("map-container"),
var_mapoptions);
var_marker.setMap(var_map);
}
google.maps.event.addDomListener(window, 'load', init_map);
</script>
</div>
</div>
</div>
</div>
</div>
</div>
I keep getting this error:
Fatal error:
Class 'EmailService' not found in (/file location)
Which is in this case uploaded to the server so it can be easily called upon on the whole website. I have never had this problem with writing and using a class. What am I possibly doing wrong? A lot more people have posted the same question about this error before, but they seem to have a different setup.
You can not include file by URL.
You have to use path of File location on server.
This is wrong
include 'https://yourdomain.nl/assets/Email_Service.php'; //ONLINE
//require base_url() . 'assets/Email_Service.php'; //LOKAAL
you have to use absolute or relative path
include "assets/Email_Service.php"; //relative path
include "<directory_path_of_your_project_on_server>/assets/Email_Service.php"; //absolute path
How to get Server file Location
create test.php in your root of with below content
<?php
echo dirname(__FILE__);
die;
execute above from browser, will be display path of your project on server and use that path.

my script has php mailer error

Could you guys help me with following problem:
my code:
<?php
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if ($_POST['submit']) {
if (!$_POST['name']) {
$error="<br/>- S'il vous plaît entrez votre nom";
}
if (!$_POST['email']) {
$error.="<br/>- S'il vous plaît entrez votre email adresse";
}
if (!$_POST['message']) {
$error.="<br/>- S'il vous plaît entrez le message";
}
if (!$_POST['check']) {
$error.="<br/>- s'il vous plaît confirmer que vous êtes humain";
}
if ($error) {
$result='<div class="alert alert-danger" role="alert"> <strong> oups, vous avez un erreur : </strong>'.$error.'</div>';
} else {
mail("1992rax#gmail.com", "contact message", "<br> Name: ".$_POST['name']."<br> Email: ".$_POST['email']."<br> Message: ".$_POST['message'],$headers);
$result='<div class="alert alert-success" role="alert"> merci votre message a été envoyer</div>';
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<title>fowaj project website</title>
<meta charset="utf-8" >
<meta name="author" content="oussama el badaoui" >
<meta name="description" content="this is an website comunity gallery of images hummour">
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<link rel="icon" href="favicon.png">
<!--[if IE]><link rel="shortcut icon" href="favicon.ico"><![endif]-->
<!-- Bootstrap main css -->
<link href="layout/css/bootstrap.css" rel="stylesheet">
<!-- custom css -->
<link href="layout/css/custom.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">
<img src="layout/images/logo.png" alt="fowaj project" />
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Accueil <span class="sr-only">(current)</span></li>
<li>Contacte</li>
<li>Politique de confidentialité</li>
<li>termes et conditions</li>
<li>à propose</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
</form>
<li>Connexion</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<section id="contact">
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>contact formulaire </h1>
<?php echo $result;?>
<p> envoyer votre message par cette formulaire</p>
<form method="post" role="form">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="enter votre nome" value="<?php echo $_POST['name'];?>">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="enter votre email" value="<?php echo $_POST['email'];?>">
</div>
<div class="form-group">
<textarea name="message" rows="5" class="form-control" placeholder="enter votre message ..."><?php echo $_POST['message'];?></textarea>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="check"> je suis humain
</label>
</div>
<div align="center">
<input type="submit" name="submit" class="btn btn-secondary" value="envoyer le message" />
</div>
</form>
</div>
</div>
</div>
</section>
<footer>
<div class="list-group col-md-4">
<a class="list-group-item active">Catégories:</a>
<a class="list-group-item" href="#">Caricatures</a>
<a class="list-group-item" href="#">Cinéma et tv</a>
<a class="list-group-item" href="#">Politique</a>
<a class="list-group-item" href="#">enfants</a>
<a class="list-group-item" href="#">animaux</a>
</div>
<div class="list-group col-md-4">
<a class="list-group-item active">les Pages de site:</a>
<a class="list-group-item" href="contact.php">Contacter Nous</a>
<a class="list-group-item" href="Privacy-policy.htm">Politique de confidentialité</a>
<a class="list-group-item" href="term-and-conditions.htm">termes et conditions</a>
<a class="list-group-item" href="about-us.htm">à propose de Nous</a>
<a class="list-group-item" href="#" data-toggle="modal" data-target="#regModal" >ajouter votre image</a>
</div>
<div class="list-group col-md-4">
<a class="list-group-item active">média sociaux:</a>
<a class="list-group-item" href="http://facebook.com/fowajproject" target="new">facebook</a>
<a class="list-group-item" href="http://twitter.com/fowajproject" target="new">twitter</a>
<a class="list-group-item" href="http://youtube.com/fowajproject" target="new">youtube</a>
<a class="list-group-item" href="http://plus.google.com/fowajprojetc" target="new">google plus</a>
</div>
<div class="col-md-12 col-sm-12 footer-info">
copyright © 2016 fowaj project made in morocco by oussama el badaoui
</div>
</footer>
</body>
</html>
You haven't defined $header!!! At the top of your file you have:
<?php
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
You are appending with .= something to a variable that doesn't exist!
Instead, simply define $headers with =:
<?php
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
That should do the trick.
You should add the code from the dropbox link you gave me in your first post.
You should try this:
if (isset($_POST['submit']) && $_POST['submit']) {
if (!$_POST['name']) {
$error = "<br/>- S'il vous plaît entrez votre nom";
}
if (!$_POST['email']) {
$error = "<br/>- S'il vous plaît entrez votre email adresse";
}
if (!$_POST['message']) {
$error = "<br/>- S'il vous plaît entrez le message";
}
if (!$_POST['check']) {
$error = "<br/>- s'il vous plaît confirmer que vous êtes humain";
}
if ($error) {
$result='<div class="alert alert-danger" role="alert"> <strong> oups, vous avez un erreur : </strong>'.$error.'</div>';
} else {
mail("1992rax#gmail.com", "contact message", "<br> Name: ".$_POST['name']."<br> Email: ".$_POST['email']."<br> Message: ".$_POST['message'],$headers);
$result ='<div class="alert alert-success" role="alert"> merci votre message a été envoyer</div>';
}
}

Categories