开发者

ASIHTTPRequest + PHP Form

I am sending some information to a php script of mine which in return sends an e-mail.

Here's the script:

<?php
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_PO开发者_运维技巧ST ['from'];
$headers = "From: Test";
if (mail($to,$subject,$message,$headers))
{
echo "Message sent.";
}
else
{
echo "Failed to send message.";
}
?>

My implementation works fine, the e-mail gets sent with the data I want to be sent - but I want to attach an image as well. My PHP knowledge is near zero, so I was wondering if someone could be so kind an help me out with my script?

Here's my iPhone implementation of ASIHTTPRequest:

datarequest = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.example.com/email.php"]];

[datarequest setPostValue:to forKey:@"to"];

if (self.message != nil)
{
[datarequest setPostValue:[NSString stringWithFormat:@"%@\n\n%@",self.message,description.text] forKey:@"message"];
}

else
{
[datarequest setPostValue:[NSString stringWithFormat:@"%@",description.text] forKey:@"message"];
}

[datarequest setPostValue:subject forKey:@"subject"];
NSData *imageData = UIImagePNGRepresentation([images lastObject]);
[datarequest addData:imageData forKey:@"image"];//here's the image that I want to add to the email


Attaching a file using mail() is possible, but requires rather complicated fiddling with multipart messages.

The usual recommendation is to use an advanced PHP mailer like Swiftmailer. Attaching files is shown here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜