1

I want to harden my SPF setting.

However I have trouble testing my SPF setting.

I want to be able send a test email to try out my new SPF settings.

Most of the resource on internet seems to be use a similar php script, which looks something like this:

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n";
mail($to, $subject, $message, $headers);
?>

(The above comes from the website here: https://dylan.tweney.com/2017/10/25/how-to-fake-an-email-from-almost-anyone-in-under-5-minutes/)

I am not familiar with php at all. When I run it on my macbookpro, it throws this error:

Parse error: syntax error, unexpected '$subject' (T_VARIABLE) in /Users/antkong/myproject/_test_mail/test.php on line 5

Here is the command: php -n -f test.php

and the version of my php run time is

$ php -version
PHP 7.1.23 (cli) (built: Feb 22 2019 22:19:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

My questions:

  1. What do I need to run this php script successfully?

  2. I don't need to stick to php. I am happy to use other language such as python. I wonder if there is a counterpart of the php script above written in python or other language which is easier to set up and run?

1

There's nothing wrong with your code there. What you're getting is a code compile error, and your code is syntactically fine.

I'm running your code just dumping the variables rather than trying to send an email:

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n";
var_dump($to, $subject, $message, $headers);
?>

Which outputs:

string(18) "nobody@example.com"
string(11) "the subject"
string(5) "hello"
string(29) "From: webmaster@example.com
"

I can make a similar error appear by removing one of the semicolons from the code as such:

<?php
$to      = 'nobody@example.com' //removed semicolon here
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n";
var_dump($to, $subject, $message, $headers);
?>

Which outputs:

Parse error: syntax error, unexpected '$subject' (T_VARIABLE) in F:\test.php on line 3

Which even in itself is different from the "error in line 5" you're getting. My suggestion is that you're not running the code you think you are. Double check test.php and go from there.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.