Jump to content
Swift

Pre-processing Emails With Php

Recommended Posts

I'm trying to set up some automation for incoming emails from Amazon and Green Metropolis. The ultimate aim is to have any orders from one venue remove the item from sale at the others. First, though, I need to get to grips with the basics.

 

I have a testing email address which is very creatively called testing@swiftbooks.co.uk

 

I have a filter to pipe incoming email on that address to a simple PHP script called mailproc.php

 

All mailproc does (at the moment) is send an email so I know it has run. This is the script:

 

#!/usr/bin/php

<?php

// read from stdin

$fd = fopen("php://stdin", "r");

// mail( "dday@swiftbooks.co.uk", "TEST Executed", "Woohoo!", "From: testing@swiftbooks.co.uk" );

mail( "dday@swiftbooks.co.uk", "TEST Executed", "Woohoo!");

return 0

?>

 

The script executes and I get the expected "Woohoo!" email on dday@swiftbooks.co.uk but I also get a permanent failure email:

 

This message was created automatically by mail delivery software.

 

A message that you sent could not be delivered to one or more of its

recipients. This is a permanent error. The following address(es) failed:

 

pipe to |/home/mytchuserid/etc/mailproc.php

generated by testing@swiftbooks.co.uk

 

The following text was generated during the delivery attempt:

 

------ pipe to |/home/mytchuserid/etc/mailproc.php

generated by testing@swiftbooks.co.uk ------

 

Content-type: text/html

 

 

------ This is a copy of the message, including all the headers. ------

 

.....

.....

 

Nothing I've tried seems to eliminate the failure message. If I change the subject (which stops mailproc running) I don't get the failure message so whatever is wrong is in that area. Can anyone see what I'm doing wrong?

 

Once I get that sorted out I can move on a bit further.

Share this post


Link to post
Share on other sites

You don't have any headers defined in your mail statement. Not sure if that's what's causing it though.

 

><?php

$Name = "sender"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command :)
?>

Share this post


Link to post
Share on other sites

I followed the simple example from http://w3schools.com/php/func_mail_mail.asp hard-coding the recipient, subject and body as I know all of this is going to be junked once the basics are working.

 

<?php

 

$txt = "First line of text\nSecond line of text";

 

// Use wordwrap() if lines are longer than 70 characters

$txt = wordwrap($txt,70);

 

// Send email

mail("somebody@example.com","My subject",$txt);

?>

 

Perhaps if I sleep on it I'll figure it out in the morning!

Edited by Swift

Share this post


Link to post
Share on other sites

I'll just use a temporary log file and worry about the mail problem later.

 

In the meantime if anyone has any ideas ....

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...