在PHP中,可以使用多种方法在单独线程上发送电子邮件。以下是一些常见的方法:
$email = "user@example.com";
$subject = "Test email";
$message = "This is a test email";
$headers = "From: sender@example.com\r\n";
$command = "echo '$message' | mail -s '$subject' -a '$headers' '$email'";
popen($command, "r");
$email = "user@example.com";
$subject = "Test email";
$message = "This is a test email";
$headers = "From: sender@example.com\r\n";
$command = "echo '$message' | mail -s '$subject' -a '$headers' '$email'";
exec($command);
$email = "user@example.com";
$subject = "Test email";
$message = "This is a test email";
$headers = "From: sender@example.com\r\n";
$command = "echo '$message' | mail -s '$subject' -a '$headers' '$email'";
shell_exec($command);
$email = "user@example.com";
$subject = "Test email";
$message = "This is a test email";
$headers = "From: sender@example.com\r\n";
$pid = pcntl_fork();
if ($pid == -1) {
die("Could not fork");
} elseif ($pid) {
// We are the parent
pcntl_wait($status);
} else {
// We are the child
$command = "echo '$message' | mail -s '$subject' -a '$headers' '$email'";
shell_exec($command);
exit(0);
}
class EmailThread extends Thread {
private $email;
private $subject;
private $message;
private $headers;
public function __construct($email, $subject, $message, $headers) {
$this->email = $email;
$this->subject = $subject;
$this->message = $message;
$this->headers = $headers;
}
public function run() {
$command = "echo '$this->message' | mail -s '$this->subject' -a '$this->headers' '$this->email'";
shell_exec($command);
}
}
$email = "user@example.com";
$subject = "Test email";
$message = "This is a test email";
$headers = "From: sender@example.com\r\n";
$thread = new EmailThread($email, $subject, $message, $headers);
$thread->start();
请注意,这些方法可能需要在服务器上安装和配置适当的邮件发送工具,例如sendmail或postfix。此外,这些方法可能存在安全风险,因此在实际应用中应该谨慎使用。