Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
<pre lang="HTML">
<div class="col-sm-6">
						<form id="request" class="row suscribe" action="request-form.php" method="post" accept-charset="utf-8">
							<div class="col-sm-12">
								<input type="text" class="form-control" placeholder="Name" name="name">
								<input type="email" class="form-control" placeholder="Email" name="email">
							</div>
							<div class="col-sm-12">
								<input type="number" class="form-control" placeholder="Phone" name="phone">
								<select class="form-control" name="program">
	                    			<option>Select Current Education</option>
	                    			<option>10th / 12th</option>
	                    			<option>Graduation</option>
	                    			<option>Post Graduation</option>
	                    			<option>CA / CS</option>
	                    			<option>Working Professional</option>
                                </select>
							</div>
							<div class="text-center">
								<button type="submit" class="btn btn-default text-center" >class="icon-info"> Request Course Information</button>
							</div>		
						</form>
					</div>


PHP
<?php


	$name        = $_POST['name'];
	$email       = $_POST['email'];
	$phone       = $_POST['phone'];
	$program     = $_POST['program'];

	$to="pkbansal991@gmail.com";
	$subject="New Enquiry";

	$body=" 
	    Message sent from website form\n	
		Name: $name\n
		Phone Number: $phone\n
		Email: $email\n	
		Program selection: $program
		";
	if($email=="") {
	echo "<div class='alert alert-danger'>
			  <a class='close' data-dismiss='alert'>×</a>
			  Warning! Please fill all the fields.
		  </div>";
	} else {
	mail($to,$subject,$body);
	echo "<div class='alert alert-success'>
			  <a class='close' data-dismiss='alert'></a>
			  Thank you for your message!
		  </div>";
	}
?>


What I have tried:

Tried all the possible ways found on Google & Youtube
Posted
Updated 29-May-18 0:01am
Comments
Jinto Jacob 29-May-18 5:15am    
when you ask a question try to be specific. Here you are not specifying what is the error. please give details about the error.
OriginalGriff 29-May-18 5:18am    
What have your tried?
Where are you stuck?
What does it do that you didn't expect, or not do that you did?
.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - and we don't even know what you want that code to do!
Use the "Improve question" widget to edit your question and provide better information.

1 solution

PHP itself can not send mail. It requires a running and configured mail server on the hosting system which is accessed by the PHP mail() function after configuration in the php.ini file.

But the PHP mail() function should not be used anymore nowadays where SSL is required.

The solution is to use one of the PHP mail frameworks like GitHub - PHPMailer/PHPMailer: The classic email sending library for PHP[^] or GitHub - swiftmailer/swiftmailer: Comprehensive mailing tools for PHP[^].

Once you have installed your preferred mail framework configure it and adapt the example code from the documentation. For using Gmail you will find many examples by searching the web for something like "php gmail <name_of_the _framework>".

Finally you have to configure the used Gmail account to allow connections from less secure apps: Allow or disallow less secure apps to access accounts - G Suite Administrator Help[^].

A final tip:
Never post sensitive information here. This includes email addresses as part of code snippets. I suggest to edit your question using the green 'Improve question' link to anonymise your Gmail address.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900