bodyless email

A

Anonymous

Guest
Hi, I'm new and I should say, I really don't know much about this. I have made a webpage to collect homework. The homework is just multiple choice questions. First I asked the students to send me their answers in an email. They did not follow my instructions, some of them made a mess of it. So I thought, "Use textboxes and radio buttons." However, if the emails were written correctly, I could download them and mark them with my little Python program, no problem

You can have a look here: www,fastmarker.com If you look, please click through to week9, that is the first time I've tried using php mail().

I'll post here thankyouW9.php which sends the mail. This is all just learnt from forums and youtube, very primitive I'm afraid.

Code:
//should mail the contact form
<?php
$studentnr = $_POST['sn'];
$q1 = $_POST['1'];
$q2 = $_POST['2'];
$q3 = $_POST['3'];
$q4 = $_POST['4'];
$q5 = $_POST['5'];
$q6 = $_POST['6'];
$q7 = $_POST['7'];
$q8 = $_POST['8'];
$q9 = $_POST['9'];
$q10 = $_POST['10'];
$q11 = $_POST['11'];
$q12 = $_POST['12'];
$q13 = $_POST['13'];
$q14 = $_POST['14'];
$q15 = $_POST['15'];
$q16 = $_POST['16'];


$body = "

Studentnr = ".$studentnr."
Q1 = ".$q1."
Q2 = ".$q2."
Q3 = ".$q3."
Q4 = ".$q4."
Q5 = ".$q5."
Q6 = ".$q6."
Q7 = ".$q7."
Q8 = ".$q8."
Q9 = ".$q9."
Q10 = ".$q10."
Q11 = ".$q11."
Q12 = ".$q12."
Q13 = ".$q13."
Q14 = ".$q14."
Q15 = ".$q15."
Q16 = ".$q16."


";

$to1 = "myMail@fastmarker.com";
$to2 = "myMail@foxmail.com";
$subject = $studentnr . "Week9";

mail($to1, $subject, $body);
mail($to2, $subject, $body);

header("Location: email_success.php");

?>

I receive the emails ok. I can see them in my email on my computer. The body part looks like this:

Studentnr = 1725010130
Q1 = B
Q2 = B
Q3 = F
Q4 = E
Q5 = T
Q6 = T
Q7 = T
Q8 = T
Q9 = B
Q10 = F
Q11 = F
Q12 = C
Q13 = F
Q14 = F
Q15 = C
Q16 = D


However when I run the python program to download the mails for marking, the body is None. I get this error:

Number of unseen messages is 46
UID is 236
1725010132Week9
Message subject is 1725010132Week9
Message body is None
Traceback (most recent call last):
File "./getAnswersFromEmail17BEv3.py", line 66, in <module>
text = message.text_part.get_payload().decode(message.text_part.charset)
TypeError: decode() argument 1 must be str, not None

I am a rank amateur at this. Can you please offer some advice, tips, links? Why does my email have no body, although I can read it in the email?
 
In mail() to, subject and body arguments are mandatory, So please print these values before mail send, otherwise code is right.
 
Back
Top