Jump to content

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:




// 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.

Link to comment
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.



$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 :)

Link to comment
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.




$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
Link to comment
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.

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...