PHP not sending email

A simple answer was already given to you. If you find this hard to do, then programming isn’t for you. Programming consists of a lot of problem solving, self teaching, and self awareness. If you do not have any of those, you won’t get very far.

People find that the syntax for any programming language is hard. I say it’s not. Knowledge doesn’t come to you, you have to learn it yourself. This is where self teaching comes from. If you can’t find answers yourself before asking a question, you’ll always end up back at the start.

Now. Use PHPMailer as the default mail() function is not reliable and has been an issue on some live hosts. Here is an important reminder why you should not use the default mail() function.

i am learning and to say the current php mail i used i learnt myself getting it wasnt as when i started the only thing i knew was the <?php and ?> tags nothing else i played with it before but this time ive been learning im not expecting answers for everything i just got carried away just wanted to actually know why my php wasnt working i dont know phpmailer thats why i hesitate over it i dislike using plugins or other software just me and notepadd++

what do you mean by default mail() is there another way of doing it?

PHPMailer isn’t a plugin. It’s a 3rd party library that is an alternative for sending emails. If you haven’t read what I have posted before, please go back and read it thoroughly. What I mean by “default mail() function” is that the mail() function comes with PHP by default. That is all. This function isn’t reliable because it fails at times. Just like you, I was once a noob too. I used to send emails using the default mail() function too. Shortly after using it, I started to see that my emails weren’t being sent. I kept searching online for answers, but I could not find the exact problem I was having. Long after, I found out myself that the mail() function fails at times even with a proper mail server. So I gave up on it and started using PHPMailer. Haven’t turned back since.

1 Like

alright thx for letting me know :slight_smile: uhhm i started downloading phpmailer yesterday amd i didnt get a readme got V6 of phpmailer and i dont know how to install it i extracted into Xampp/htdocs and im trying to figure out what to do coz i create a index.php to test the phpmailer and it doesnt do anything it shows all my coding on the page and i do have apche switched on any help or point me to a website that can help me instal phpmailer ive been looking and all i get is how to create my first phpmailer nothing about how to install it or if there is more than one package to instal nothing…

There are some articles here on PHPmailer.

1 Like

Thx for the URL i have now got it to work as it seems im still able to use the original php verification i have all i need to do is replace mail() to the phpmailer info

now i want make that phpmailer file like an external link so it can execute it from a seperate file therefore making it 'global without having to write it over and over and also keep it out of the ‘root’ folder.

so i just want to know is there a way to link to external files outside of root like in xampp link files outside of htdocs.

basicly only fill this part in the php.mail i used earlier and the rest before that into a seperate php file.

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

otherwords something like this:

<?php 

/* Define Veriables */
	$name = test_input($_POST["name"]);
	$srn = test_input($_POST["surname"]);
	$email = test_input($_POST["send"]);
	$hidden = $_POST["website"]);
	$msg = test_input($_POST["message"]);
	
/* Filter Remove extra spacing */
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}


/* When Submit is called */
if($_SERVER["REQUEST_METHOD"] == "POST"){
/* filter Name Empty  and characters */
	if(empty($name)){
		$name = 0;
		$errname = "* Name Field has not been filled in";
	}else{
		if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
			$name = 0;
			$errname = "* Name Field contains elements other than plain text";
		}else{
			$name = 1;
			$errname = "";
		}	
	}

/* filter Surname Empty  and characters */
	if(empty($srn)){
		$srn = 0;
		$errsrn = "";
	}else{
		if (!preg_match("/^[a-zA-Z ]*$/",$srn)) {
			$srn = 0;
			$errsrn = "</br>* Surname Field contains elements other than plain text";
		}else{
			$srn = 1;
			$errsrn = "";
		}
	}
	
/* filter email Empty  and characters */
	if(empty($email)){
		$email = 0;
		$erremail = "</br>* Your Email Field has not been filled in";
		
	}else{
		if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
			$email = 0;
			$erremail = "</br>* Email Field Does not contain @ symbol and or suffixis";
		}else{
			$email = 1;
			$erremail = "";
		}
	}

/* check if hidden field is filled in */
	if(empty($hidden){
		$hidden = 1;
		$errhidden = "</br>Somehow you answered a hidden input field";
	else{
		$hidden = 0;
		$errhidden = "";
	}
/* filter message Empty  and characters */
	if(empty($msg)){
		$msg = 0;
		$errmsg = "</br>* Error: message not displayed what are you trying to tell us?";
		
	}else{
		$msg = 1;
		$errmsg = "";
	}
	
	if($name + $srn + $email + $msg + $hidden > 4){
		
	$name = test_input($_POST["name"]);
	$srn = test_input($_POST["surname"]);
	$email = test_input($_POST["send"]);
	$msg = test_input($_POST["message"]);
	$succmsg = "Your message has been successfully delivered!</br></br> Feel Free to check out our social media </br></br>or</br></br> select an option at the navigation to take you to our website.";
	
	
/* link external php here */
$ext = /* Code or file path */
/* */

	$mail->Subject = "From:" ','.$Name ',' .$srn ',' "(" ','.$email ',' ")";
	$mail->Body    = $msg;
	$mail->AltBody = "From: ***";

if(!$mail->send()) {
		
		echo "Dear";
		echo " ";
		echo $name;
		echo " ";
		echo $srn;
		echo "</br>";
		echo "</br>";
		echo "</br>";
		echo $succmsg;
		echo "</br>";
		echo "</br>";

	}else{
		
		$name = "User";
		$srn = "";
		$email = "From: Mr Laptop.co.za";
		$msg = "It Appears Your Email was unsuccessful, This could be due to incomplete Field(s).";
	
		echo "Dear";
		echo " ";
		echo $name;
		echo " ";
		echo $srn;
		echo "</br>";
		echo "</br>";
		echo $msg;
		echo "</br>";
		echo "</br>";
		echo '<b style="color:red;font-size:14px;">';
		echo $errname;
		echo $errsrn;
		echo $erremail;
		echo $errmsg;
		echo $errhidden;
		echo "</b>";
		echo "</br>";
		echo "</br>";
		echo '<a href="http://localhost/contact.html" style="color:#fff;font-size:15px;">Back to form</a>';
	
	}
}
?>

Ok so i fixed my issue in this PHP file but now just to be extra carefull how do i link outside of my root folder for instance its situated in htdocs of xampp how do i select a file outside of htdocs as it is more secure

use of PHP would be great ive looked on the internet for answers but all say i need to edit php.ini to use alias and i also heard its not completely safe there and i dont want to have to do the same on the server as they may not even be using xamp or wampp.

honestly I dont know what the server uses for php support but is there a way to select files outside of htdocs but still in the server eg in xampp and not in the files inside of htdocs

You can select files for inclusion that are below the root folder. Use ../ to go back a folder level.

include_once "../includes/myInclude.php" ;

i do that and it always keeps telling me directory doesnt exist

like instance i have my directories like this:
c:/xampp/htdocs/bla.php
and other file:
c:/xampp/Other/bla.php

the htdocs is the web root anything in there gets used at localhost therefor anything outside of htdocs doesnt work i want to access it from outside the htdocs for security reasons.

Using …/Other/bla.php calls:
c:/xampp/htdocs/Other/bla.php

and gives error file not found.

basicly after i added the php external file into the php file it worked but because it was inside of htdocs therefor can still be accessed if so i decided to create an ini file or php file outside the htdocs file to use as veriables to execute my files without revealing important info.
and thats what im trying i tried parsed_ini but it didnt work file directory is still the issue as it gives me file not found

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.