Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I cannot send all the details to the email id in this contact form, i don't know if i'm putting the right code at the right place or not, I have only mentioned the labels in the php file below for the ones which i am able to send. Please can someone help me with the code, and where do i put it? My company is really behind my ass for this one. and i suppose this is my last option :'(

What I have tried:

PHP FILE
<?php
	$msg = "";

	if (isset($_POST['submit'])) {

		require 'phpmailer/PHPMailerAutoload.php';

		function sendemail($to, $from, $fromName, $body, $attachment = "") {
			$mail = new PHPMailer();
			$mail->setFrom($from, $fromName);
			$mail->addAddress($to);
			$mail->addAttachment($attachment);
			$mail->Subject = 'Contact Form - Email';
			$mail->Body = $body;
			$mail->isHTML(false);

			return $mail->send();
		}

		$name = $_POST['username'];
		$email = $_POST['email'];
		$body = $_POST['body'];

		$file = "attachment/" . basename($_FILES['attachment']['name']);
		if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
		    if (sendemail('info@alabdouligroup.com', $email, $name, $body, $file)) {
				$msg = 'Email sent!';
				
			} else
				$msg = 'Email failed!';
		} else
			$msg = "Please check your attachment!";
	}
?>


HTML FILE

<h3>Your Personal Details</h3>

<form method="post" enctype="multipart/form-data">
<table border="0" cellpadding="5" cellspacing="0">
<tr> <td style="width: 50%">
<label for="First_Name">First name *</label><br />
<input name="username" type="text" maxlength="50" style="width: 260px" />
</td> <td style="width: 50%">
<label for="Last_Name">Last name *</label><br />
<input name="Last_Name" type="text" maxlength="50" style="width: 260px" />
</td> </tr> <tr> <td colspan="2">
<label for="Email_Address">Email *</label><br />
<input name="email" type="text" maxlength="100" style="width: 535px" />
</td> </tr> <tr> <td colspan="2">
<label for="Portfolio">Portfolio website</label><br />
<input name="Portfolio" type="text" maxlength="255" value="http://" style="width: 535px" />
</td> </tr> <tr> <td colspan="2">
<label for="Position">Position you are applying for *</label><br />
<input name="body" type="text" maxlength="100" style="width: 535px" />
</td> </tr> <tr> <td>
<label for="Salary">Salary requirements</label><br /> <input name="Salary" type="text" maxlength="50" style="width: 260px" /> </td> <td>
<label for="StartDate">When can you start?</label><br />
<input name="StartDate" type="text" maxlength="50" style="width: 260px" />
</td> </tr> <tr> <td>
<label for="Phone">Phone *</label><br />
<input name="Phone" type="text" maxlength="50" style="width: 260px" />
</td> <td>
<label for="Fax">Fax</label><br />
<input name="Fax" type="text" maxlength="50" style="width: 260px" />
</td> </tr> <tr> <td colspan="2">
<label for="Relocate">Are you willing to relocate?</label><br />
<input name="Relocate" type="radio" value="Yes" checked="checked" /> Yes      
<input name="Relocate" type="radio" value="No" /> No      
<input name="Relocate" type="radio" value="NotSure" /> Not sure
</td> </tr> <tr> <td colspan="2">
<label for="Organization">Last company you worked for</label><br />
<input name="Organization" type="text" maxlength="100" style="width: 535px" />
</td> </tr> <tr> <td colspan="2">
<label for="Reference">Reference / Comments / Questions</label><br />
<textarea name="Reference" rows="7" cols="40" style="width: 535px"></textarea>
</td> </tr> <tr> <td colspan="2" style="text-align: center;">
			<input type="file" name="attachment" required><br>
			<input type="submit" name="submit" value="Send Email">
		</td> </tr>
</table>
</form>
		<br><br>
		<?php echo $msg; ?>
Posted
Updated 14-Nov-17 1:00am
Comments
ThilinaMD 13-Nov-17 10:00am    
$body = $_POST['body']; will fetch only the data in 'body' input field which is refer to 'position you are applying for'. you have to catch all the filed values from form.
Suvendu Shekhar Giri 13-Nov-17 10:12am    
Good catch!
lookwhosback 13-Nov-17 10:57am    
can you please give me an example from the above code and make it a bit more clear to me? because the $body(position) doesn't gets send to the mail also. it's only the name and email which gets send to the mail...
Suvendu Shekhar Giri 13-Nov-17 10:11am    
Are you getting any error?
W Balboos, GHB 13-Nov-17 12:29pm    
You have quite a few fields in your form (with name=) which are sent to your target page, but only actually read back the data from username, email, and body. This leads to two possibilites:

1) You're requesting data that you don't need since you never do anything with it, or,
2) You need the data but don't request it.

For example, why do you need to ask them for a start date, if they will relocate, yet never retrieve this data?

You need to rethink what you're asking for, what you need, and then $_POST[] the appropriate values for your email, building a body that contains what you need it to contain.

1 solution

Your comment: "Sir i want to send all these fields to the mail, i know i didn't use the other fields except username, email and body but i want to use and send the other fields too and i'm not able to do so, this is why i'm here. Please if you can help me with that?"

This implies very strongly that you've no clue what you have - it was cut/pasted from somewhere. I will, however, give you a link so you can learn exactly how to do what you want to do:

HTML Forms[^]

If you want work done for you (and since you refer to "your company", so you're being paid for this work - realize that we do this for money, too. If we do you're work for you then we would expect to be paid for it (just like you).
 
Share this answer
 
v2
Comments
lookwhosback 14-Nov-17 23:15pm    
all i wanted was some help from the codeproject, Nevermind though.

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