0
我正在使用wamp服務器,並且在將表單值發送到電子郵件之前,我已經使用了此php腳本。我找不到我用代碼完成的工作,或者它可能會讓我的wamp服務器驚慌失措,因爲它不再發送,並且收到錯誤消息:發送消息時出現問題。通過PHP腳本發送電子郵件
代碼:
// Create the form
$contactForm = new JFormer('contactForm', array(
'submitButtonText' => 'Send Message',
));
// Add components to the form
$contactForm->addJFormComponentArray(array(
new JFormComponentSingleLineText('artistname', 'Artist Name:', array(
'validationOptions' => array('required'),
'tip' => '<p>Enter your artist name.</p>'
)),
new JFormComponentSingleLineText('trackname', 'Track Name:', array(
'tip' => '<p>Enter your track name.</p>',
'validationOptions' => array('required'),
)),
new JFormComponentSingleLineText('email', 'E-mail Address:', array(
'tip' => '<p>Enter your email address.</p>',
'validationOptions' => array('required'),
)),
new JFormComponentSingleLineText('stream', 'Link to Stream:</br>(if applicable)', array(
'tip' => '<p>Enter your link to stream.</p>'
)),
new JFormComponentSingleLineText('download', 'Download Link:', array(
'tip' => '<p>Enter your download link.</p>',
'validationOptions' => array('required'),
)),
new JFormComponentMultipleChoice('multipleChoiceType', 'Full Track or Clip:',
array(
array('label' => 'Full Track', 'value' => 'fulltrack'),
array('label' => 'Clip', 'value' => 'clip'),
),
array(
'multipleChoiceType' => 'radio',
)),
new JFormComponentSingleLineText('downloadorpurchase', 'Free Download or
Purchase Link</br>(To be included in video description)', array(
'tip' => '<p>Enter your link.</p>',
)),
new JFormComponentSingleLineText('releasedate', 'Release Date:</br>(if applicable)', array(
'tip' => '<p>Enter the release date.</p>',
)),
new JFormComponentTextArea('artistandlabel', 'Artist/Label Links:</br>(To be included in description.)', array(
'validationOptions' => array('required'),
'tip' => '<p>Enter your description.</p>',
)),
new JFormComponentMultipleChoice('iagree', 'I confirm that I own full
copyright rights and grant the THU Records to post my music in their videos. I
understand that content may be monetized with adverts.',
array(
array('label' => 'I Accept', 'value' => 'accepted'),
array('label' => 'I Do Not Accept', 'value' => 'dontaccepted'),
),
array(
'iagree' => 'radio',
'validationOptions' => array('required'),
)),
));
// Set the function for a successful form submission
function onSubmit($formValues) {
// Concatenate the name
if(!empty($formValues->name->middleInitial)) {
$name = $formValues->name->firstName . ' ' . $formValues->name->middleInitial . ' ' . $formValues->name->lastName;
}
else {
$name = $formValues->name->firstName . ' ' . $formValues->name->lastName;
}
// Prepare the variables for sending the mail
$to = '[email protected]';
$fromAddress = $formValues->email;
$trackName = $formValues->trackname;
$streamLink = $formValues->stream;
$download = $formValues->download;
$trackorclip = $formValues->multipleChoiceType;
$downloadOrPurchase = $formValues->downloadorpurchase;
$releaseDate = $formValues->releasedate;
$artistAndLabel = $formValues->artistandlabel;
$agreement = $formValues->iagree;
$artistName = $formValues->artistname;
$subject = "Submit from ".$formValues->artistname;
$message = "Artist Name : ".$artistName."\nTrack Name : ".$trackName."\n
Email : ".$fromAddress."\n Stream Link : ".$streamLink."\nDownload link
: ".$download."\nTrack or Clip : ".$trackorclip."\nDownload or Purchase
: ".$downloadOrPurchase."\n Release Date : ".$releaseDate."\n Artist
and Label Info : ".$artistAndLabel."\n Agreement : ".$agreement;
// Use the PHP mail function
$mail = mail($to, $subject, $message);
// Send the message
if($mail) {
$response['successPageHtml'] = '
<h1>Thanks for Contacting Us</h1>
<p>Your message has been successfully sent.</p>
';
}
else {
$response['failureNoticeHtml'] = '
There was a problem sending your message.
';
}
return $response;
}
// Process any request to the form
$contactForm->processRequest();
做任何人你有什麼想法可能是錯了嗎? :(