Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'PHPMailer/src/Exception.php';
- require 'PHPMailer/src/PHPMailer.php';
- require 'PHPMailer/src/SMTP.php';
- //HTML Form Removel
- function removeHTML($texttovalid){
- $texttovalid = trim($texttovalid);
- if(strlen($texttovalid)>0){
- $texttovalid = htmlspecialchars(stripslashes($texttovalid));
- }
- return $texttovalid;
- }
- //Form POST variables
- $nome = removeHTML($_POST['nome']);
- $email = removeHTML($_POST['email']);
- $msg ='';
- // Begining of validating variables
- if(isset($_POST['submit']))
- {
- $required = array("nome", "email");
- foreach($_POST as $key=>$value)
- {
- if (empty($value) && in_array($key, $required) === true)
- {
- $msg = 'Fill in required fields.';
- break 1;
- }
- if (!filter_var($email, FILTER_VALIDATE_EMAIL))
- {
- $msg = 'Invalid email';
- }
- }
- if (empty($msg) === true) {
- $body = "rNome: $nome";
- $body .= "rnE-mail: $email";
- $bodysend = utf8_decode($body);
- $mail = new PHPMailer(true); // Passing `true` enables exceptions
- try {
- //Server settings
- $mail->SMTPDebug = 1;
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'mail.dfg.pt'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'geral@xxx.com'; // SMTP username
- $mail->Password = 'xxxxxx'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587; // TCP port to connect to
- $mail->setLanguage('pt', 'PHPMailer/language/');
- //Recipients
- $mail->setFrom('geral@xxx.com', 'DFG');
- $mail->addAddress($email, $nome); // Add a recipient
- $mail->addBCC('info@xxx.com');
- //Content
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'This is a subject';
- $mail->Body = $bodysend;
- $mail->send();
- $msg = 'Thank you.';
- } catch (Exception $e) {
- $msg = 'Error occurred. Mailer Error: '. $mail->ErrorInfo;
- }
- }
- } ?>
- <div class="alert-msg"><?php echo $msg;?></div>
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
- <div class="mt-10">
- <input type="text" name="nome" placeholder="Nome" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Nome'" class="single-input">
- </div>
- <div class="mt-10">
- <input type="email" name="email" placeholder="E-mail" onfocus="this.placeholder = ''" onblur="this.placeholder = 'E-mail'" required class="single-input">
- </div>
- <div class="mt-10">
- <button type="submit" class="primary-btn hover submit-btn d-inline-flex align-items-center mt-20"><span class="mr-10">Submit</span><span class="lnr lnr-arrow-right"></span></button>
- </div>
- </form>
- PHP Notice: Undefined index: nome in /public_html/index.php on line 17
- [27-Oct-2018 14:13:57 UTC]
- PHP Notice: Undefined index: email in /public_html/index.php on line 18
Add Comment
Please, Sign In to add comment