Click here to Skip to main content
15,888,241 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have used phpmailer autoload but when form submitted its redirect perfectly on thank you page but i did not get any mail. i have tried below code:

What I have tried:

PHP
MY Code:

<?php	

//include_once 'dbconfig.php';

require 'email/phpmailer/PHPMailerAutoload.php';

//set validation error flag as false
$error = false;

//check if form is submitted
	
	if(isset($_POST['submit'])){		
		
		$name = $_POST['name'];
		$location = $_POST['location'];
		$email = $_POST['email'];
		$mobile = $_POST['mobile'];
		$msg = $_POST['mssge'];
		
		if(empty($name)){
			$error = true;			
			?>
				<script>
					alert('Please Enter Your Name.');
					window.location.href='wonder_women.php';
				</script>
			<?php
		}		
		elseif (!preg_match("/^[a-zA-Z ]+$/",$name)) {
			$error = true;			
			?>
				<script>
					alert('Name must contain only alphabets and space.');
					window.location.href='wonder_women.php';
				</script>
			<?php
		}
		elseif(empty($location)){
			$error = true;			
			?>
				<script>
					alert('Please Enter Your Location.');
					window.location.href='wonder_women.php';
				</script>
			<?php
		}	
		elseif(!filter_var($email,FILTER_VALIDATE_EMAIL)) {
			$error = true;			
			?>
			<script>
				alert('Please Enter Valid Email ID.');
				window.location.href='wonder_women.php';
			</script>
			<?php
		}
		elseif(empty($mobile)){
			$error = true;			
			?>
				<script>
					alert('Please Enter Your Mobile Number.');
					window.location.href='wonder_women.php';
				</script>
			<?php
		}	
			
    
		if (!$error) {			
			$mail = new PHPMailer;			
			$mail->setFrom('myemailid@gmail.com','myemailid');
			$mail->addAddress('myanmeemail128@gmail.com');     // Add a recipient			
			$mail->isHTML(true);                                 // Set email format to HTML
			$mail->Subject = 'Wonder Women Feedback';
			$mail->Body =
				"<p>Name : $name</p>
							<p>Location : $location</p>
							<p>Email : $email</p>
							<p>Mobile : $mobile</p>
							<p>Message : $msg</p>";
			if ($mail->send()) {
				?>
					<script>
						alert('Thank You.');
						window.location.href='wonder_women.php';
					</script>					
				<?php
			}
			else{					
				?>
					<script>
						alert('Error in submiting Story');
						window.location.href='wonder_women.php';
					</script>
				<?php
			}
		}
		
	}
	
?>
Posted
Comments
Richard MacCutchan 23-Feb-18 10:11am    
You have not set a SMTP server address as far as I can see.
David_Wimbley 24-Feb-18 1:16am    
If you didn't get the mail and your code was successful i'm not sure what you expect any of us to do. My only suggestion is to try another email service. For example, i see you are using gmail, try using outlook.com or what would be better is if you've got a personal website or something of that sort, try it using the smtp server provided by your hosting company.

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