在PHP邮件脚本中更改CGI-Mailer

时间:2017-05-31 22:53:06

标签: php

我有一个PHP脚本,可以从HTML表单发送电子邮件。问题是发件人在我的收件箱中显示为com.google.cloud.pubsub.spi.v1.Publisher publisher = Publisher.defaultBuilder(TopicName.parse("projects/" + projectId + "/topics/" + topicName)) .setChannelProvider(TopicAdminSettings .defaultChannelProviderBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(new FileInputStream(keyFile)))) .build()) .build(); ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage); messageIdFuture.get() // HANGS FOREVER!!

enter image description here

如何将发件人地址设置为发件人地址而不是GoogleCredential credential = new GoogleCredential.Builder() .setTransport(new NetHttpTransport()) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(serviceAccount) .setServiceAccountScopes(Arrays.asList(PubsubScopes.PUBSUB)) .setServiceAccountPrivateKeyFromP12File(new File(keyFile)) .build(); Pubsub pusub = new Pubsub.Builder(transport, JSON_FACTORY, credential).setApplicationName("bigquery").build(); PubsubMessage pubsubMessage = new PubsubMessage(); pubsubMessage.encodeData(message.getBytes()); PublishRequest publishRequest = new PublishRequest(); publishRequest.setMessages(Arrays.asList(pubsubMessage)); pubsub.projects().topics().publish(outputTopic, publishRequest).execute();

CGI-Mailer

2 个答案:

答案 0 :(得分:2)

您没有将additional_headers parameter传递给mail函数。通过调用mail将行更改为:

mail($to, $subject, $body, $headers);

答案 1 :(得分:0)

我建议使用PHPMailer而不是mail()。您可以在回答此问题的过程中看到如何做以后的事情:https://github.com/PHPMailer/PHPMailer

引用该问题:

$this->phpmailer->AddReplyTo($replyEmail,$fromName);  //this is email2@example.com
$this->phpmailer->SetFrom($fromEmail, $fromName); //this is email1@example.com

您可以在此处找到有关PHPMailer的更多信息:{{3}}